Labsco
github logo

java-springboot

✓ Official36,200

by github · part of github/awesome-copilot

Comprehensive best practices guide for building production-ready Spring Boot applications. Covers project structure, dependency injection patterns, and configuration management including externalized config, type-safe properties, and environment profiles Details web layer design with RESTful APIs, DTOs, validation, and global exception handling Addresses service layer statelessness, transaction management, and data access patterns using Spring Data JPA with custom queries and projections...

🔥🔥🔥🔥✓ VerifiedFreeQuick setup
🧩 One of 7 skills in the github/awesome-copilot package — works on its own, and pairs well with its siblings.

Comprehensive best practices guide for building production-ready Spring Boot applications. Covers project structure, dependency injection patterns, and configuration management including externalized config, type-safe properties, and environment profiles Details web layer design with RESTful APIs, DTOs, validation, and global exception handling Addresses service layer statelessness, transaction management, and data access patterns using Spring Data JPA with custom queries and projections...

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by github

Comprehensive best practices guide for building production-ready Spring Boot applications. Covers project structure, dependency injection patterns, and configuration management including externalized config, type-safe properties, and environment profiles Details web layer design with RESTful APIs, DTOs, validation, and global exception handling Addresses service layer statelessness, transaction management, and data access patterns using Spring Data JPA with custom queries and projections... npx skills add https://github.com/github/awesome-copilot --skill java-springboot Download ZIPGitHub36.2k

Spring Boot Best Practices

Your goal is to help me write high-quality Spring Boot applications by following established best practices.

Dependency Injection & Components

  • Constructor Injection: Always use constructor-based injection for required dependencies. This makes components easier to test and dependencies explicit.

  • Immutability: Declare dependency fields as private final.

  • Component Stereotypes: Use @Component, @Service, @Repository, and @Controller/@RestController annotations appropriately to define beans.

Web Layer (Controllers)

  • RESTful APIs: Design clear and consistent RESTful endpoints.

  • DTOs (Data Transfer Objects): Use DTOs to expose and consume data in the API layer. Do not expose JPA entities directly to the client.

  • Validation: Use Java Bean Validation (JSR 380) with annotations (@Valid, @NotNull, @Size) on DTOs to validate request payloads.

  • Error Handling: Implement a global exception handler using @ControllerAdvice and @ExceptionHandler to provide consistent error responses.

Service Layer

  • Business Logic: Encapsulate all business logic within @Service classes.

  • Statelessness: Services should be stateless.

  • Transaction Management: Use @Transactional on service methods to manage database transactions declaratively. Apply it at the most granular level necessary.

Data Layer (Repositories)

  • Spring Data JPA: Use Spring Data JPA repositories by extending JpaRepository or CrudRepository for standard database operations.

  • Custom Queries: For complex queries, use @Query or the JPA Criteria API.

  • Projections: Use DTO projections to fetch only the necessary data from the database.

Logging

  • SLF4J: Use the SLF4J API for logging.

  • Logger Declaration: private static final Logger logger = LoggerFactory.getLogger(MyClass.class);

  • Parameterized Logging: Use parameterized messages (logger.info("Processing user {}...", userId);) instead of string concatenation to improve performance.

Testing

  • Unit Tests: Write unit tests for services and components using JUnit 5 and a mocking framework like Mockito.

  • Integration Tests: Use @SpringBootTest for integration tests that load the Spring application context.

  • Test Slices: Use test slice annotations like @WebMvcTest (for controllers) or @DataJpaTest (for repositories) to test specific parts of the application in isolation.

  • Testcontainers: Consider using Testcontainers for reliable integration tests with real databases, message brokers, etc.

Security

  • Spring Security: Use Spring Security for authentication and authorization.

  • Password Encoding: Always encode passwords using a strong hashing algorithm like BCrypt.

  • Input Sanitization: Prevent SQL injection by using Spring Data JPA or parameterized queries. Prevent Cross-Site Scripting (XSS) by properly encoding output.