PluginBench
Skill
Official
Review
Audit score 70

java-springboot

github/awesome-copilot

Best practices for building high-quality Spring Boot applications with proper architecture and configuration.

What is java-springboot?

This skill provides guidance on developing Spring Boot applications following established best practices. Use it when building new Spring Boot projects or refactoring existing ones to improve code quality, maintainability, and security.

  • Organize project structure by feature/domain rather than technical layers
  • Implement constructor-based dependency injection with immutable fields
  • Configure applications using externalized YAML/properties files and type-safe configuration objects
  • Design RESTful APIs with DTOs, validation, and global exception handling
  • Manage transactions and business logic in service layer with proper separation of concerns
  • Use Spring Data JPA repositories with custom queries and projections for data access

How to install java-springboot

npx skills add https://github.com/github/awesome-copilot --skill java-springboot
Claude Code
Cursor
Windsurf
Cline

How to use java-springboot

  1. 1.Review the project structure guidelines and organize your code by feature/domain
  2. 2.Implement constructor-based dependency injection for all required dependencies
  3. 3.Configure your application using application.yml with @ConfigurationProperties for type safety
  4. 4.Design RESTful endpoints with DTOs and implement global exception handling with @ControllerAdvice
  5. 5.Encapsulate business logic in @Service classes with @Transactional for transaction management
  6. 6.Use Spring Data JPA repositories and custom @Query annotations for data access
  7. 7.Add unit tests with JUnit 5 and Mockito, and integration tests with @SpringBootTest or test slices
  8. 8.Implement Spring Security for authentication/authorization and use BCrypt for password encoding

Use cases

Good for
  • Building a new REST API microservice with proper layered architecture
  • Refactoring a Spring Boot application to use constructor injection and immutable dependencies
  • Setting up environment-specific configurations for dev, staging, and production deployments
  • Implementing authentication and authorization in a web application
  • Writing comprehensive test suites with integration tests using real databases
Who it's for
  • Java backend developers
  • Spring Boot application architects
  • DevOps engineers configuring Spring Boot deployments
  • QA engineers writing integration tests

java-springboot FAQ

Should I use constructor injection or field injection?

Always use constructor-based injection for required dependencies. It makes components easier to test, dependencies explicit, and fields immutable (private final). Avoid @Autowired field injection.

How should I handle configuration for different environments?

Use Spring Profiles with separate files like application-dev.yml and application-prod.yml. Store secrets in environment variables or dedicated tools like HashiCorp Vault or AWS Secrets Manager, never hardcode them.

Should I expose JPA entities directly in my REST API?

No, always use DTOs (Data Transfer Objects) to expose and consume data in the API layer. This decouples your API contract from your database schema.

What's the best way to handle errors in a Spring Boot application?

Implement a global exception handler using @ControllerAdvice and @ExceptionHandler annotations to provide consistent error responses across your application.

How should I organize my test suite?

Write unit tests for services using JUnit 5 and Mockito, use @WebMvcTest for controller tests and @DataJpaTest for repository tests, and use Testcontainers for reliable integration tests with real databases.

Full instructions (SKILL.md)

Source of truth, from github/awesome-copilot.


name: java-springboot description: 'Get best practices for developing applications with Spring Boot.'

Spring Boot Best Practices

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

Project Setup & Structure

  • Build Tool: Use Maven (pom.xml) or Gradle (build.gradle) for dependency management.
  • Starters: Use Spring Boot starters (e.g., spring-boot-starter-web, spring-boot-starter-data-jpa) to simplify dependency management.
  • Package Structure: Organize code by feature/domain (e.g., com.example.app.order, com.example.app.user) rather than by layer (e.g., com.example.app.controller, com.example.app.service).

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.

Configuration

  • Externalized Configuration: Use application.yml (or application.properties) for configuration. YAML is often preferred for its readability and hierarchical structure.
  • Type-Safe Properties: Use @ConfigurationProperties to bind configuration to strongly-typed Java objects.
  • Profiles: Use Spring Profiles (application-dev.yml, application-prod.yml) to manage environment-specific configurations.
  • Secrets Management: Do not hardcode secrets. Use environment variables, or a dedicated secret management tool like HashiCorp Vault or AWS Secrets Manager.

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.