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.

More: all Spring Boot (Java) rules · all GitHub Copilot rules

Related rules

Spring Boot 4 CLAUDE.md

CLAUDE.md for Spring Boot 4 (Spring Framework 7) services on Java 25: null-safety, HTTP clients, testing, and migrations.

Claude Code (CLAUDE.md)Spring Boot (Java)

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

ASP.NET Core Copilot instructions

Copilot instructions for ASP.NET Core on .NET 9/10: minimal APIs, EF Core, nullable types, and xUnit tests.

GitHub Copilot.NET / ASP.NET Core

Go Copilot path instructions

Path-specific Copilot instructions (.instructions.md) for Go 1.27 code: errors, context, stdlib routing, and tests.

GitHub CopilotGo

Java + Gradle Copilot path instructions

Path-specific Copilot instructions for Java 25 LTS code built with Gradle: records, null safety, and JUnit 5 tests.

GitHub CopilotJava

Laravel Copilot instructions

GitHub Copilot instructions for Laravel 11+ apps with Eloquent, Pest, and Form Requests.

GitHub CopilotLaravel

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.