Generated banner for Java Springboot
Generated logo for Java Springboot

Java Springboot

GitHubOfficialFirst committed by jduboisDistributed by GitHub

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Write and review application code in an existing Spring Boot 3/4 project: controllers, validation and ProblemDetail errors, Spring Data JPA/JDBC, RestClient and HTTP interfaces, configuration properties, Kafka/AMQP, caching, scheduling, virtual threads, AOT and startup tuning. Use when adding or changing features. To scaffold a new project use create-spring-boot-java-project instead.
— the description by jdubois

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides rules and best practices for developing features within an established Spring Boot 3 or 4 project. It covers essential areas including configuration management, data access, REST API design, messaging, and startup optimization. The skill emphasizes maintaining consistency with existing project conventions, verifying changes through the project's build system, and avoiding implicit upgrades or unauthorized infrastructure additions.

What it does

  • Provides guidance on implementing controllers, validation, and ProblemDetail error handling.
  • Offers patterns for Spring Data JPA/JDBC, RestClient, and HTTP interfaces.
  • Details configuration management using type-safe properties and profiles.
  • Covers integration of messaging systems like Kafka and AMQP, caching, and scheduling.
  • Explains startup tuning techniques including AOT, CDS, and virtual threads.
  • Enforces strict adherence to existing project build tools and versioning conventions.

When to use it

  • When you need to add new features or modify existing code in a Spring Boot 3 or 4 project.
  • When implementing new configuration properties or managing environment-specific settings.
  • When optimizing application startup times or memory usage using AOT or CDS.
  • When integrating new messaging, caching, or database components into an existing codebase.

Advantages

  • Ensures consistency by matching existing project structure, versions, and naming conventions.
  • Promotes safe development practices by requiring build verification before finalizing changes.
  • Provides clear guidance on modern Spring Boot features like virtual threads and AOT.
  • Reduces configuration errors through type-safe property binding and validation.

Usage examples

“How do I add a new configuration property for my mail service in my Spring Boot 4 project?”
The agent will provide a code snippet for a type-safe record using @ConfigurationProperties and explain how to register it using @ConfigurationPropertiesScan.
“I need to implement a REST endpoint that returns a custom error using ProblemDetail.”
The agent will guide you to create a @RestControllerAdvice and demonstrate how to map exceptions to the RFC 7807 ProblemDetail format.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/github/java-springboot/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip java-springboot.zip -d .agents/skills

Documentation by jdubois

Spring Boot application development

Opinionated rules plus a router to deeper references. Code samples in the references were compiled and run on Spring Boot 4.1.1 (Spring Framework 7) and, where they differ, on Boot 3.5.16 (Framework 6.2). Boot 3 vs 4 differences are marked "Boot 3" / "Boot 4" in each reference.

Before writing code

  1. Detect, do not assume: read pom.xml/build.gradle(.kts) for the Spring Boot version, Java version, starters in use (spring-boot-starter-web is Boot 3, spring-boot-starter-webmvc is Boot 4), persistence (JPA, JDBC), the migration tool, the test setup, and the package layout and naming conventions of the existing code. Match them.

  2. Never upgrade Spring Boot, Java or dependencies implicitly. A Boot 3 -> 4 move is a deliberate task (spring-boot-4-migration).

  3. Ask before adding infrastructure: a broker (Kafka, RabbitMQ), a cache provider, a new database, or a scheduler/async setup. Add only what the user requested, with the Boot-managed version (no explicit version for BOM-managed artifacts, never latest).

  4. Verify every change with the project's own build: ./mvnw verify or ./gradlew build (plain mvn/gradle if no wrapper). Integration tests need Docker when they use Testcontainers.

Router

TaskRead
Repositories, projections, pagination, N+1, @Transactional, auditing, Flyway/Liquibase, Spring Data JDBCreferences/data.md
Controllers, validation, ProblemDetail, RestClient, @HttpExchange, API versioning, OpenAPI, JSpecifyreferences/rest-api.md
Kafka/AMQP, @Cacheable/Caffeine, @Scheduled, @Async, virtual threads, outboxreferences/messaging-caching.md
@ConfigurationProperties, profiles, secrets, config import, Docker Compose / Testcontainers at dev timereferences/configuration.md
AOT, CDS/AppCDS, lazy initialization, native imagereferences/aot-and-startup.md

If these standalone skills are installed, also use them for their topic; otherwise rely on the official docs: java-hibernate-jpa (JPA mapping), spring-boot-testing (tests), spring-security (authentication, authorization, CSRF/CORS), spring-observability (metrics, tracing, Actuator, logs), create-spring-boot-java-project (project defaults, Boot 3 vs 4 build changes), java-add-graalvm-native-image-support (native executable).

Core rules

  • Structure and layers: package by feature; constructor injection; controllers return DTOs/records, never entities; services own the transaction.

  • Validation and errors: Bean Validation on request records with @Valid; one @RestControllerAdvice returning ProblemDetail. JSpecify annotations document nullability only and do not validate.

  • Jackson: Boot 4 uses Jackson 3 (tools.jackson.databind.*, JsonMapper; annotations stay in com.fasterxml.jackson.annotation); Boot 3 uses Jackson 2 (com.fasterxml.jackson.databind.*, ObjectMapper).

  • Slice-test gotcha: put @EnableJpaAuditing, @EnableCaching, @EnableAsync, @EnableScheduling on dedicated @Configuration classes, not on the @SpringBootApplication class, or slices such as @DataJpaTest fail to start (for example, no CacheManager). Slices do not scan @Configuration classes: @Import the one a test needs.

  • Proxied beans: @Cacheable, @Async and @Transactional work through proxies: they do nothing on self-invocation or on private/final methods; test them through the injected bean.

Checklist

  • [ ] Versions, build tool and conventions detected; starters match the Boot major

  • [ ] No new infrastructure or dependency without the user's agreement

  • [ ] ./mvnw verify / ./gradlew build passes; secrets absent from code, properties and logs

See also: Spring Boot reference https://docs.spring.io/spring-boot/reference/, Spring Framework reference https://docs.spring.io/spring-framework/reference/, Spring Data https://docs.spring.io/spring-data/commons/reference/.

Files

references/rest-api.md

REST API (Spring MVC)

Verified on Boot 4.1.1 (Framework 7) and, where noted, Boot 3.5.16 (Framework 6.2). Security of endpoints: spring-security. Test slices (@WebMvcTest, MockMvcTester, @RestClientTest): spring-boot-testing.

Starters and packages (Boot 3 vs 4)

Boot 3Boot 4
Web starterspring-boot-starter-webspring-boot-starter-webmvc (+ spring-boot-starter-webmvc-test)
RestClient auto-configBoot 3.2+ only, in the web starter; unavailable on 3.0/3.1add spring-boot-starter-restclient
@WebMvcTestorg.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestorg.springframework.boot.webmvc.test.autoconfigure.WebMvcTest (also AutoConfigureMockMvc)
Mock a bean@MockitoBean (3.4+; @MockBean removed in 4)@MockitoBean (org.springframework.test.context.bean.override.mockito)
JSONJackson 2 ObjectMapperJackson 3 tools.jackson.databind.json.JsonMapper bean

Jackson 2 databind may still be on the classpath transitively (for example through Spring for Apache Kafka), which is not a reason to code against it in Boot 4. A temporary Jackson 2 bridge exists (spring-boot-jackson2, see the Boot 4 migration guide and spring-boot-4-migration).

Controllers and validation

public record CreateOrderRequest(@NotBlank String customer, @Positive BigDecimal total) {}

@RestController
@RequestMapping("/api/orders")
class OrderController {
	private final OrderService orders;
	OrderController(OrderService orders) { this.orders = orders; }

	@PostMapping
	ResponseEntity<OrderSummary> create(@Valid @RequestBody CreateOrderRequest req) {
		var created = orders.create(req);
		return ResponseEntity.created(URI.create("/api/orders/" + created.id())).body(created);
	}
}
  • Nouns for resources, plural, HTTP verbs for actions; 201 + Location on create, 204 on delete, 404 via exception, not null.

  • Request/response types are records, separate from entities. Bean Validation (jakarta.validation.constraints.*) goes on the record components. In Framework 6.1+ (Boot 3.2+), put constraints directly on @RequestParam/@PathVariable parameters and omit class-level @Validated: built-in MVC method validation raises HandlerMethodValidationException. Class-level @Validated instead enables AOP validation, which raises ConstraintViolationException by default and needs its own error handler. On older Framework versions, use that AOP approach and map the exception to HTTP 400 explicitly.

  • Never accept unbounded input: cap size for pagination, limit request body size at the server/proxy.

  • Return Page<T> only if exposing Spring Data's page JSON is acceptable; for a stable public contract return your own record PageResponse<T>(List<T> content, long total, int page, int size). Pagination parameters and stable sorting: data.md.

Errors: ProblemDetail (RFC 9457)

@RestControllerAdvice
class ApiExceptionHandler extends ResponseEntityExceptionHandler {

	@ExceptionHandler(OrderNotFoundException.class)
	ProblemDetail notFound(OrderNotFoundException ex) {
		var pd = ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, ex.getMessage());
		pd.setTitle("Order not found");
		return pd;
	}
}
  • Extending ResponseEntityExceptionHandler turns Spring MVC's own exceptions (validation MethodArgumentNotValidException and, in Framework 6.1+, HandlerMethodValidationException, malformed JSON, unsupported media type, invalid API version) into application/problem+json (verified: validation errors give status 400 problem details; the unknown-API-version error gives 400). Test invalid query/path parameters as well as invalid request bodies; class-level @Validated must not divert them to an unhandled AOP exception.

  • Verified the same advice works unchanged on Boot 3.5.16. Do not return exception messages that contain internals (SQL, class names) in detail; log them, return a stable message, and add a custom property (pd.setProperty("code", "ORDER_NOT_FOUND")) for clients.

  • Test with jsonPath("$.status"), jsonPath("$.title") and content().contentTypeCompatibleWith(MediaType.APPLICATION_PROBLEM_JSON).

API versioning (Boot 4 / Framework 7 only)

Framework 7 has first-class API versioning; it does not exist in Framework 6 (verified: @GetMapping(version = ...) does not compile on Boot 3.5.16, use URL prefixes such as /api/v1/... there).

spring.mvc.apiversion.use.header=X-API-Version
spring.mvc.apiversion.default=1
spring.mvc.apiversion.supported=1,2
@GetMapping(value = "/{id}", version = "1")  OrderSummary getV1(@PathVariable Long id) { ... }
@GetMapping(value = "/{id}", version = "2")  OrderSummary getV2(@PathVariable Long id) { ... }

Alternatives to the header are ...use.path-segment, ...use.query-parameter and ...use.media-type-parameter. Verified: a request without the header uses the default version, and an unsupported version (3) returns a 400 problem detail ("Invalid API version"). Version only when a breaking change is unavoidable; additive changes do not need a new version.

Calling other services

RestClient (Boot 3.2+/4)

RestClient and RestClientAdapter require Framework 6.1+; Boot's builder auto-configuration starts in 3.2. On Boot 3.0/3.1, retain the project's existing RestTemplate rather than generating this example or implicitly upgrading dependencies.

On Boot 4 add spring-boot-starter-restclient (it was in the verified build, which injected the builder; Boot 3.2+: RestClient.Builder comes with the web starter). Inject the builder (RestClient.Builder), never create clients without it, so that observability and customizers apply (spring-observability). Set base URL and timeouts through properties/customizers, not per call. Prefer RestClient over RestTemplate (maintenance mode) and over WebClient unless you are reactive.

@Bean
RestClient ratesClient(RestClient.Builder builder) {
	return builder.baseUrl("https://rates.example.com").build();
}
// usage: ratesClient.get().uri("/rates/{c}", "EUR").retrieve().body(Rate.class);

retrieve() throws RestClientResponseException on 4xx/5xx; map to your own exceptions at the boundary.

HTTP interfaces (@HttpExchange)
@HttpExchange("/rates")
public interface RatesClient {
	record Rate(String currency, double value) {}

	@GetExchange("/{currency}")
	Rate get(@PathVariable String currency);
}
  • Boot 4 / Framework 7: register with @ImportHttpServices and configure the URL in properties (verified):

    @Configuration(proxyBeanMethods = false)
    @ImportHttpServices(group = "rates", types = RatesClient.class)
    class HttpClientsConfig {}
    spring.http.serviceclient.rates.base-url=https://rates.example.com

    then inject RatesClient like any bean.

  • Boot 3.2+ / Framework 6.1+: @ImportHttpServices does not exist (verified). Build the proxy manually:

    var client = HttpServiceProxyFactory.builderFor(RestClientAdapter.create(restClient)).build().createClient(RatesClient.class);

    (org.springframework.web.client.support.RestClientAdapter, same on Boot 4.)

  • Boot 3.0/3.1 / Framework 6.0: if WebClient is already available, HTTP interfaces can use WebClientAdapter with the Framework 6.0 HttpServiceProxyFactory API. Otherwise retain the existing RestTemplate setup; do not introduce RestClientAdapter or add WebFlux implicitly.

  • Tests (Boot 3.2+/4): MockRestServiceServer.bindTo(RestClient.Builder) records and answers requests without a network (verified for both the manual and the Boot 4 setups); use WireMock only for contract-style tests with real HTTP.

OpenAPI (springdoc)

springdoc is not Spring-Boot-managed: pick the line that matches the Boot major from the springdoc compatibility table and pin it. Verified: org.springdoc:springdoc-openapi-starter-webmvc-ui 3.1.1 on Boot 4.1.1 serves /v3/api-docs including controller paths (springdoc 2.x targets Boot 3). Expose Swagger UI (/swagger-ui.html) only in non-production profiles or behind authentication; allow the paths in spring-security. Document with @Operation/@ApiResponse sparingly; the controller signature and validation annotations already feed the schema.

Null-safety with JSpecify (Framework 7 / Boot 4)

Spring Framework 7 and Boot 4 annotate their APIs with JSpecify (org.jspecify.annotations): everything is non-null unless marked @Nullable. In your code:

  • Add @NullMarked in package-info.java (verified to compile on Boot 4.1.1 where org.jspecify:jspecify is already on the classpath) and mark nullable parameters, returns and fields with org.jspecify.annotations.Nullable.

  • Replace org.springframework.lang.Nullable/NonNull (deprecated in Framework 7) with JSpecify when touching those files.

  • JSpecify is documentation for tools (IDE, NullAway, Error Prone) and does not validate at runtime. For request validation keep using jakarta.validation.constraints.NotNull/@NotBlank. Optional: add NullAway to the build only if the project asks for it.

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

First committed by
GitHub avatar of jduboisjdubois
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/java-springboot · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
jdubois

AutoGineer is not affiliated with or endorsed by jdubois or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download java-springboot.zip