Custom Copilot instructions for Java 21+ development with Spring Boot, records, sealed classes, and modern patterns.
## Java Copilot Custom Instructions
You are a Java expert for GitHub Copilot. Follow these conventions for all Java code:
### Java Version
- Target Java 21+ features: records, sealed classes, pattern matching, virtual threads
- Use `var` for local variables when the type is obvious from context
- Prefer records over POJOs for immutable data carriers
- Use sealed interfaces to model closed type hierarchies
### Code Style
- Follow Google Java Style Guide with 100-character line width
- Use `final` on local variables and parameters where practical
- Prefer `Optional<T>` return types over returning null
- Never catch `Exception` or `Throwable` directly unless re-throwing
### Spring Boot Conventions
- Constructor injection only; no `@Autowired` on fields
- Use `@RestController` with `@RequestMapping` at class level
- Return `ResponseEntity<T>` from controller methods
- Use `@Valid` on request body parameters with Jakarta validation annotations
- Service layer handles business logic; controllers handle HTTP mapping only
### Data Access
- Spring Data JPA repositories extending `JpaRepository<T, ID>`
- Use `@Transactional(readOnly = true)` for read operations
- Write custom queries with `@Query` JPQL, avoid native SQL unless necessary
- Use `Specification<T>` for dynamic filters
- Always use parameterized queries, never string concatenation
### Testing
- JUnit 5 with `@DisplayName` for readable test names
- `@SpringBootTest` for integration tests, `@WebMvcTest` for controller tests
- Use `@MockitoExtension` with `@Mock` and `@InjectMocks`
- AssertJ fluent assertions: `assertThat(actual).isEqualTo(expected)`
### Error Handling
- Global `@RestControllerAdvice` exception handler
- Custom exception hierarchy: `AppException -> NotFoundException, ValidationException`
- Return RFC 7807 Problem Detail responses
### Logging
- SLF4J with Lombok `@Slf4j` annotation
- Use parameterized logging: `log.info("User {} logged in", userId)`Free to copy and use. Compatible with GitHub Copilot, GPT-5.
Add to .github/copilot-instructions.md in your Java/Spring Boot repository for consistent Copilot suggestions.
Initial release
Sign in and download this prompt to leave a review.