Index of every page on this site: llms.txt
All skills
github avatar

/java-springboot

@f10fdb8 official
by githubgithub/awesome-copilot42k stars
5,426
Run it yourself

Write and review application code in an existing Spring Boot 3/4 project: controllers, validation and ProblemDetail errors, Spring Data JPA/JDBC, RestClient and HTTP interfaces, configuration properties, Kafka/AMQP, caching, scheduling, virtual threads, AOT and startup tuning. Use when adding or changing features. To scaffold a new project use create-spring-boot-java-project instead.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/java-springboot

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesdata.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Data access (Spring Data JPA, Spring Data JDBC)

For mapping problems (N+1 theory, equals/hashCode, cascades, locking, batching) use the java-hibernate-jpa skill; for PostgreSQL defaults and Docker Compose use create-spring-boot-java-project (references/database.md); for @DataJpaTest and Testcontainers use spring-boot-testing. This file covers the Spring layer on top. Verified with Spring Data JPA on Boot 4.1.1 and Boot 3.5.16 (same code).

Repositories

public interface OrderRepository extends JpaRepository<PurchaseOrder, Long> {

	interface CustomerView { Long getId(); String getCustomer(); }   // interface projection

	Page<CustomerView> findByStatus(PurchaseOrder.Status status, Pageable pageable);

	@Query("select new com.example.demo.OrderSummary(o.id, o.customer, o.total) from PurchaseOrder o where o.customer = :customer")
	Page<OrderSummary> summaries(String customer, Pageable pageable);   // record DTO

	@EntityGraph(attributePaths = "items")
	Optional<PurchaseOrder> findWithItemsById(Long id);                 // fetches the collection in one query
}
  • Derived queries for simple lookups; @Query (JPQL) once the method name gets long; @Query(nativeQuery = true) only when JPQL cannot express it. Named parameters (:customer) bind by name when compiled with -parameters (the Boot parent POM and Gradle plugin enable it; verified without @Param).
  • Projections: return interface projections (closed: only getters for the needed columns) or record DTOs (select new ... with the fully qualified name) for read endpoints.
  • Pagination: Page<T> runs an extra count query; use Slice<T> when the total is not needed. Always sort on a stable, unique column (Sort.by("id")); cap the page size from user input (Math.min(size, 100)). Never combine pagination with a collection JOIN FETCH (in-memory paging; see java-hibernate-jpa).
  • N+1: fix per query with @EntityGraph or JOIN FETCH, keep associations LAZY, and assert statement counts in a test (hibernate.generate_statistics).
  • spring.jpa.open-in-view=false; load what the response needs inside the transaction and map to DTOs there.
  • Boot 4: JPA slice classes moved: org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest, org.springframework.boot.jpa.test.autoconfigure.TestEntityManager, org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase (Boot 3: org.springframework.boot.test.autoconfigure.orm.jpa.* and ...autoconfigure.jdbc.*). Starter: spring-boot-starter-data-jpa (+ spring-boot-starter-data-jpa-test for tests).

Transactions

  • @Transactional on service methods (the use-case boundary), not on controllers or repositories. Reads: @Transactional(readOnly = true).
  • Keep transactions short: no HTTP calls, messaging sends or file I/O inside; publish events after commit with @TransactionalEventListener(phase = AFTER_COMMIT) or an outbox (references/messaging-caching.md).
  • Spring rolls back on unchecked exceptions only; use rollbackFor for checked ones. Self-invocation bypasses the proxy.
  • Services return DTOs, so lazy associations are never touched after the transaction ends.

Auditing

@Configuration(proxyBeanMethods = false)
@EnableJpaAuditing
class JpaAuditingConfig {}   // not on the @SpringBootApplication class

@Entity @EntityListeners(AuditingEntityListener.class)
class PurchaseOrder {
	@CreatedDate Instant createdAt;
	@LastModifiedDate Instant lastModifiedAt;
}

@DataJpaTest does not scan @Configuration classes: @Import(JpaAuditingConfig.class) in the test, otherwise createdAt stays null (verified). For @CreatedBy/@LastModifiedBy provide an AuditorAware<String> bean (usually from the security context; see spring-security).

Schema management

Follow the schema management rule of java-hibernate-jpa (prototype: update; production: Flyway/Liquibase with ddl-auto=validate; externally managed: none). With Spring Boot:

  • Boot 4: add spring-boot-starter-flyway (and org.flywaydb:flyway-database-postgresql for PostgreSQL) or spring-boot-starter-liquibase; the auto-configuration lives in the starter. Boot 3: org.flywaydb:flyway-core (+ flyway-database-postgresql) or liquibase-core.
  • Migrations in src/main/resources/db/migration/V1__init.sql; never edit an applied migration, add a new version. Each migration is one reviewable unit; use ddl-auto=validate so entity/schema drift fails at startup (verified: a Flyway-created schema passes validate for the entities above).
  • Add them only when the user wants versioned migrations or the app is headed to production; do not add Flyway to a project whose schema is managed elsewhere.

Spring Data JDBC (alternative)

Choose it for simple aggregates without lazy loading, sessions or dirty tracking: aggregate roots are loaded and saved as a whole, and there is no persistence context. Starter spring-boot-starter-data-jdbc (do not put it next to data-jpa in the same module unless you configure repository scanning explicitly: both would try to claim repositories).

public record Book(@Id Long id, String title, @MappedCollection(idColumn = "book") Set<Chapter> chapters) {
	public record Chapter(String name) {}
}

public interface BookRepository extends ListCrudRepository<Book, Long>, PagingAndSortingRepository<Book, Long> {
	List<Book> findByTitleStartingWith(String prefix);
}
  • You own the schema (schema.sql with spring.sql.init.mode=always, or Flyway/Liquibase as above); there is no ddl-auto.
  • null id means insert; the saved copy carries the generated id (repo.save returns it: use the return value with records).
  • Boot 4 test slice: org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest (verified with a Testcontainers PostgreSQL, @AutoConfigureTestDatabase(replace = NONE)).
  • Not a drop-in for JPA: no @EntityGraph, no lazy associations, references between aggregates are by id.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning5d5 checks · Risk SAFE
  • Gen Agent Trust Hub12d

    The skill provides safe and idiomatic guidance for Spring Boot 3 and 4 development. It incorporates several security best practices, such as proper secret management (advising against committing credentials), input validation, and secure API design. A minor risk factor is present as the agent is instructed to read external project build and configuration files, which could theoretically contain malicious instructions designed to influence the agent.

  • Socket5d

    No alerts

  • Snyk12d

    Risk: LOW · No issues

  • Runlayer9mo

    1/1 file flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f10fdb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated last month
  • Testing
  • java
  • spring-boot
  • rest-api
  • jpa
  • spring-security
  • configuration
  • dependency-injection

README badge

README badge for github/awesome-copilot/java-springboot

Instructs Claude to follow Spring Boot best practices for Java applications, covering project structure, dependency injection, configuration management, REST API design, data access patterns, testing, and security. Targets developers building Spring Boot applications with Maven or Gradle and using Spring Data JPA for persistence.

Generated from the current SKILL.md.

Does this skill cover Spring Security configuration?
Yes. It includes guidance on using Spring Security for authentication and authorization, password encoding with BCrypt, and preventing SQL injection and XSS attacks.
What testing frameworks does this skill recommend?
JUnit 5 and Mockito for unit tests, @SpringBootTest for integration tests, test slice annotations like @WebMvcTest and @DataJpaTest for isolated testing, and Testcontainers for reliable database and external service testing.
Does this skill cover data layer patterns?
Yes. It covers Spring Data JPA repositories, custom queries with @Query, the JPA Criteria API, and DTO projections for efficient data fetching.
What configuration approach does this skill recommend?
Use externalized configuration via application.yml, @ConfigurationProperties for type-safe binding, Spring Profiles for environment-specific configs, and environment variables or secret management tools like Vault or AWS Secrets Manager for secrets.
Does this skill address error handling?
Yes. It recommends implementing a global exception handler using @ControllerAdvice and @ExceptionHandler for consistent error responses across the application.

Generated from the current SKILL.md. These answers refresh after source changes.