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.

referencesmessaging-caching.md

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

Messaging, caching, scheduling, async

Ask before adding a broker, a cache provider or a scheduler/async setup to an existing project: each one adds infrastructure and operational cost. When the user agrees, use the Boot-managed versions (no explicit version for Spring-managed artifacts). Verified on Boot 4.1.1 (JDK 26 runtime, --release 25); Boot 3 differences noted where known. Tests for these: spring-boot-testing; tracing/metrics for them: spring-observability.

Kafka (Spring for Apache Kafka)

  • Boot 4: spring-boot-starter-kafka (+ spring-boot-starter-kafka-test). Boot 3: org.springframework.kafka:spring-kafka (no starter; version managed by the Boot BOM).
  • Producer: KafkaTemplate<String, String>; consumer: @KafkaListener.
@Component
class Events {
	private final KafkaTemplate<String, String> template;
	Events(KafkaTemplate<String, String> template) { this.template = template; }

	void publish(String key, String payload) { template.send("orders", key, payload); }

	@KafkaListener(topics = "orders", groupId = "demo")
	void on(String payload) { /* must be idempotent: delivery is at-least-once */ }
}
spring.kafka.bootstrap-servers=${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
spring.kafka.consumer.auto-offset-reset=earliest
  • Consumers must be idempotent (at-least-once delivery); decide on a retry/dead-letter strategy (DefaultErrorHandler with DeadLetterPublishingRecoverer) before going to production.
  • Keep payloads as versioned DTOs (records); avoid sending JPA entities.
  • Test with a real broker through Testcontainers (verified: send then receive in a @SpringBootTest):
import org.testcontainers.kafka.KafkaContainer;

@TestConfiguration(proxyBeanMethods = false)
public class TestcontainersConfiguration {
	@Bean @ServiceConnection
	KafkaContainer kafkaContainer() { return new KafkaContainer(DockerImageName.parse("apache/kafka-native:4.0.0")); }
}

Boot 4 uses Testcontainers 2.x (artifact org.testcontainers:testcontainers-kafka); Boot 3 uses 1.x (artifact org.testcontainers:kafka). The example uses org.testcontainers.kafka.KafkaContainer, available in recent 1.x releases as well as 2.x; check that the project's BOM-managed version supports apache/kafka-native. Do not substitute the legacy org.testcontainers.containers.KafkaContainer: it requires a confluentinc/cp-kafka image. If the project's older Testcontainers version lacks the modern class or native-image support, use the legacy class with a compatible pinned Confluent image instead, without implicitly upgrading dependencies. Pin the image tag, never latest. Wait with a CountDownLatch/Awaitility, not Thread.sleep.

RabbitMQ / AMQP (not verified in this skill's builds)

spring-boot-starter-amqp (Boot 3 and 4), RabbitTemplate to send, @RabbitListener to consume, @ServiceConnection with the Testcontainers RabbitMQ module for tests. Declare queues/exchanges as Queue/TopicExchange/Binding beans, use Jackson2JsonMessageConverter-style JSON converters only after checking the Jackson major in use (Boot 4 = Jackson 3), and configure a dead-letter exchange. Check the Spring AMQP reference for the exact converter class names for your version before generating code.

Transactional outbox

Publishing to a broker inside a database transaction is not atomic: a crash between commit and send loses the message. When messages must not be lost, write the event to an outbox table in the same transaction as the state change, and have a relay (scheduled poller or CDC such as Debezium) publish and mark it sent. Consumers stay idempotent. Do not implement it unless the user needs that guarantee; for events that can be lost, @TransactionalEventListener(phase = AFTER_COMMIT) is simpler.

Caching with Caffeine

  • Dependencies: spring-boot-starter-cache (Boot 4 + test starter spring-boot-starter-cache-test; Boot 3 the same starter name) and com.github.ben-manes.caffeine:caffeine (BOM-managed).
@Configuration(proxyBeanMethods = false)
@EnableCaching
class CachingConfig {}   // a dedicated class, not the @SpringBootApplication class

@Service
class RateService {
	@Cacheable("rates")                                   // key = method arguments
	public Rate expensive(String currency) { ... }

	@CacheEvict(value = "rates", allEntries = true)
	public void evict() {}
}
spring.cache.type=caffeine
spring.cache.cache-names=rates
spring.cache.caffeine.spec=maximumSize=500,expireAfterWrite=10m
  • Verified on Boot 4.1.1: second call is served from cache, evict() forces a reload. Always set maximumSize and an expiry; unbounded caches are memory leaks.
  • Cache immutable DTOs/records, not managed JPA entities. The cache is per JVM: with several instances use a distributed cache (Redis) only if the user asks for it, and expect stale data across nodes with Caffeine.
  • @Cacheable is proxy-based: self-invocation and private methods bypass it. Do not cache methods with side effects or null returns you do not intend to cache.
  • Enabling caching in @SpringBootApplication breaks slice tests that do not register a CacheManager (verified: @DataJpaTest fails with "No qualifying bean of type CacheManager"), hence the dedicated @Configuration.
  • To expose cache statistics in Micrometer call recordStats (Caffeine spec recordStats); otherwise Boot logs a warning that the cache is not recording statistics (observed).

Scheduling

@Configuration(proxyBeanMethods = false)
@EnableScheduling
class SchedulingConfig {}

@Scheduled(fixedDelayString = "${app.tick:PT10S}")   // or cron = "0 0 * * * *", zone = "UTC"
void cleanup() { ... }

Verified: @Scheduled(fixedDelayString = "${...:100ms}") runs on Boot 4.1.1. Prefer fixedDelay over fixedRate to avoid overlapping runs. @Scheduled runs on every instance: with several replicas use a lock (ShedLock) or an external scheduler; add that only after asking. Scheduled methods take no arguments and must not throw unhandled exceptions silently: log and handle.

Async and virtual threads

spring.threads.virtual.enabled=true     # Java 21+, Boot 3.2+

With the property set, Boot runs Tomcat/Jetty request handling, @Async tasks (through the auto-configured task executor) and other Boot-managed executors on virtual threads. Verified on Boot 4.1.1: an @Async method reports Thread.currentThread().isVirtual() == true.

@Configuration(proxyBeanMethods = false)
@EnableAsync
class AsyncConfig {}

@Async
public CompletableFuture<Result> compute() { ... }   // return void or CompletableFuture
  • Needs Java 21+; on Boot 3 the property exists from 3.2. Do not enable it on Java 17.
  • Virtual threads help blocking I/O workloads (JDBC, HTTP). They do not speed up CPU-bound work. Pool sizes become the bottleneck: size the HikariCP pool deliberately and consider limits on downstream calls. Before JDK 24, synchronized blocks around blocking calls pin the carrier thread; prefer ReentrantLock there.
  • @Async is proxy-based like @Transactional: the caller must be another bean, and the transaction/security context does not follow into the async thread unless propagated.
  • With @Async returning void, exceptions are lost unless an AsyncUncaughtExceptionHandler is configured.

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.