Home › Spring Boot (Java) › Spring Boot 3 Copilot instructions

Spring Boot 3 Copilot instructions

Copilot instructions for Spring Boot 3.x services on Java 21 with records, JPA, validation, and Testcontainers.

GitHub CopilotSpring Boot (Java)

How to use

Save this as .github/copilot-instructions.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.github/copilot-instructions.mdDownload  
# Spring Boot 3 service (Java 21)

## Build
- Maven: `./mvnw verify` (Gradle projects: `./gradlew check`). Run locally with `./mvnw spring-boot:run`.

## Code style
- Constructor injection only (final fields, no `@Autowired` on fields). Lombok only if the project already uses it.
- DTOs are Java `record`s; never expose JPA entities from controllers.
- Package by feature: `com.acme.orders.{OrderController, OrderService, OrderRepository, dto}`.
- Validate request bodies with `@Valid` and Jakarta constraints (`@NotBlank`, `@Size`). Errors return RFC 9457 `ProblemDetail` from a `@RestControllerAdvice`.
- `@Transactional` belongs on service methods, read-only where possible (`@Transactional(readOnly = true)`).
- JPA: avoid N+1 with fetch joins or `@EntityGraph`; paginate with `Pageable`. Schema changes are Flyway migrations in `db/migration`, never `ddl-auto=update`.
- Use `RestClient` for outbound HTTP (not `RestTemplate` in new code). Virtual threads are allowed via `spring.threads.virtual.enabled=true` if already enabled.
- Config with `@ConfigurationProperties` records, not scattered `@Value`.

## Tests
- `@WebMvcTest` for controllers, `@DataJpaTest` with Testcontainers Postgres for repositories, `@SpringBootTest` only for a few integration paths.

## Don't
- Don't catch `Exception` and return 200, or log secrets/PII.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.