Guides Java development with Spring Boot, Spring Security, JPA/Hibernate, and Maven/Gradle. Covers project setup, hexagonal architecture, N+1 query fixes, transactional rules, and REST error handling.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
# Spring Initializr CLI (Spring Boot 3.x, Java 21)
curl https://start.spring.io/starter.zip \
-d type=maven-project \
-d language=java \
-d bootVersion=3.3.0 \
-d groupId=com.example \
-d artifactId=myapp \
-d javaVersion=21 \
-d dependencies=web,data-jpa,security,actuator,validation,flyway \
-o myapp.zip && unzip myapp.zip
Structure des profils :
src/main/resources/
application.yml # valeurs communes
application-dev.yml # dev local (H2, logs DEBUG)
application-prod.yml # prod (connexion pool, logs INFO)
Typer la configuration avec @ConfigurationProperties plutôt que @Value :
@ConfigurationProperties(prefix = "app.payment")
public record PaymentProperties(String apiUrl, Duration timeout, int maxRetries) {}
| Contexte | Approche recommandée |
|---|---|
| API CRUD simple | Couches Controller → Service → Repository |
| Domaine métier riche | Hexagonale (ports/adapters) + DDD |
| Gros projet (>5 équipes) | Multi-modules Maven par bounded context |
| Microservices | 1 module = 1 deployable, API contract-first OpenAPI |
Organisation par feature (pas par couche technique) dans les projets moyens/grands :
com.example.payment/
PaymentController.java
PaymentService.java
PaymentRepository.java
PaymentDto.java # record Java 21
Payment.java # entité JPA
Problème N+1 — détecter et corriger :
// Mauvais : génère N+1 requêtes
List<Order> orders = orderRepo.findAll();
orders.forEach(o -> o.getItems().size()); // lazy load en boucle
// Correct : fetch join explicite
@Query("SELECT o FROM Order o JOIN FETCH o.items WHERE o.status = :status")
List<Order> findWithItems(@Param("status") OrderStatus status);
// Ou via @EntityGraph
@EntityGraph(attributePaths = {"items", "customer"})
List<Order> findByStatus(OrderStatus status);
Règles @Transactional :
public du Service, jamais sur le Repository@Transactional(readOnly = true) sur les lectures → flush mode OFF + optimisations HibernateREQUIRES_NEW uniquement si isolation réelle nécessaire (audit, log d'erreur)Migration de schéma avec Flyway :
db/migration/
V1__create_orders.sql
V2__add_payment_status.sql
Handler d'erreur global :
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(EntityNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ProblemDetail handleNotFound(EntityNotFoundException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, ex.getMessage());
}
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ProblemDetail handleValidation(MethodArgumentNotValidException ex) {
var pd = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST);
pd.setProperty("errors", ex.getBindingResult().getFieldErrors()
.stream().map(e -> e.getField() + ": " + e.getDefaultMessage()).toList());
return pd;
}
}
DTO avec record Java 21 + validation :
public record CreateOrderRequest(
@NotBlank String customerId,
@NotEmpty List<@Valid OrderItemRequest> items,
@PositiveOrZero BigDecimal discount
) {}
Documentation OpenAPI (SpringDoc) :
# application.yml
springdoc:
api-docs.path: /api-docs
swagger-ui.path: /swagger-ui.html
show-actuator: false
Configuration minimale JWT Resource Server :
@Configuration
@EnableMethodSecurity
public class SecurityConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(s -> s.sessionCreationPolicy(STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health").permitAll()
.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
.build();
}
}
Sécurisation par méthode :
@PreAuthorize("hasRole('ADMIN') or #userId == authentication.name")
public UserDto getUser(String userId) { ... }
CORS : configurer via CorsConfigurationSource bean, pas via @CrossOrigin sur chaque contrôleur.
RabbitMQ — pattern listener avec retry :
@RabbitListener(queues = "payment.queue",
containerFactory = "retryContainerFactory")
public void handlePayment(PaymentEvent event) {
paymentService.process(event);
}
Kafka — configuration producer idempotent :
spring.kafka.producer:
enable-idempotence: true
acks: all
retries: 3
Dead-letter queue : configurer x-dead-letter-exchange sur la queue principale + consumer séparé sur la DLQ pour replay manuel.
E2E (WireMock + Testcontainers) ← peu nombreux, lents
Integration (@SpringBootTest) ← couverture des flux critiques
Slice (@WebMvcTest, @DataJpaTest) ← rapides, ciblés
Unit (JUnit 5 + Mockito) ← majoritaires
Test slice REST :
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@Autowired MockMvc mvc;
@MockBean OrderService orderService;
@Test
void createOrder_returns201() throws Exception {
given(orderService.create(any())).willReturn(new OrderDto("123"));
mvc.perform(post("/orders")
.contentType(APPLICATION_JSON)
.content("""{"customerId":"C1","items":[]}"""))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.id").value("123"));
}
}
Testcontainers (PostgreSQL) :
@Testcontainers
@SpringBootTest
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> pg = new PostgreSQLContainer<>("postgres:16");
@DynamicPropertySource
static void props(DynamicPropertyRegistry r) {
r.add("spring.datasource.url", pg::getJdbcUrl);
r.add("spring.datasource.username", pg::getUsername);
r.add("spring.datasource.password", pg::getPassword);
}
}
management:
endpoints.web.exposure.include: health,info,prometheus,metrics
endpoint.health.show-details: when-authorized
metrics.export.prometheus.enabled: true
Corréler logs + traces :
// Micrometer Tracing auto-injecte traceId/spanId dans MDC si Zipkin/OTLP est configuré
// Ajouter dans logback-spring.xml :
// %X{traceId} %X{spanId}
Virtual threads (Java 21 + Spring Boot 3.2+) pour améliorer le throughput I/O-bound :
spring.threads.virtual.enabled: true
| Piège | Conséquence | Correction |
|---|---|---|
@Autowired sur champ | Tests unitaires impossibles sans contexte Spring | Injection par constructeur (final + @RequiredArgsConstructor) |
@Transactional sur méthode private | Transaction silencieusement ignorée (proxy CGLIB) | Déplacer sur méthode public ou extraire dans un autre bean |
Appel interne this.method() transactionnel | Bypass du proxy → pas de transaction | Injecter le bean lui-même ou restructurer |
| Entité JPA exposée dans le Controller | Couplage fort, risque de lazy init exception | Toujours mapper vers DTO avant de sérialiser |
FetchType.EAGER par défaut sur @OneToMany | Full table join à chaque chargement | Garder LAZY + fetch join explicite quand nécessaire |
@SpringBootTest pour tout | Suite de tests lente (contexte complet) | Préférer @WebMvcTest / @DataJpaTest slices |
Secrets dans application.yml commités | Fuite de credentials | Variables d'environnement ou Spring Cloud Config / Vault |
Ignorer readOnly = true | Flush inutile + dirty checking sur toutes les entités | @Transactional(readOnly = true) sur toutes les méthodes de lecture |
switch, virtual threads activés par défaut en Spring Boot 3.2+.ProblemDetail (RFC 7807) pour les erreurs REST, @HttpExchange pour les clients HTTP déclaratifs (remplace Feign dans les nouveaux projets).spring-aot-maven-plugin; tester en CI avec ./mvnw -Pnative test../mvnw dependency-check:check (OWASP) ou Dependabot; ne jamais logger les JWT ni les payloads contenant des PII.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests"./claude-skills-collection:dev-java-spring-advisorfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collectionOther plugins' skills for the same job