java-spring-best-practices

java-spring-best-practices is a skill for Claude Code, Codex from cosbort/agent-skills. It costs 104 tokens per session (2,897 once invoked), scanned A, original, MIT.

A development guide for building Java applications with Spring Boot, a framework for creating web APIs and services. It covers common choices for data transfer, errors, logging, testing, concurrency, and deployment.

In plain words
What is it for?
Use it when creating Spring Boot APIs, microservices, or enterprise applications with validation, standard error responses, integration tests, observability, and native builds.
Why use it?
It gives a shared set of practices for keeping larger Java services organized and easier to operate.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cosbort/agent-skills/java-spring-best-practices
Any agent
npx skills add cosbort/agent-skills --skill java-spring-best-practices
Clone the repo
git clone --depth 1 https://github.com/cosbort/agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for java-spring-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/cosbort/agent-skills/java-spring-best-practices.svg)](https://agentmods.dev/skills/cosbort/agent-skills/java-spring-best-practices)
Your own site
<a href="https://agentmods.dev/skills/cosbort/agent-skills/java-spring-best-practices"><img src="https://agentmods.dev/badge/skills/cosbort/agent-skills/java-spring-best-practices.svg" alt="Measured on agentmods" height="20"></a>
Per session 104 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,897 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00104 $0.02897
Opus 5 $0.00052 $0.01448
Sonnet 5 $0.00021 $0.00579
Haiku 4.5 $0.00010 $0.00290

Measured 4d ago against content hash c90d42bc2991, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

java-spring-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

java-spring-best-practices/SKILL.md · 410 lines

How it starts

The opening of the file, as written. The whole thing — 410 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Java Spring Boot Best Practices v2.0

Production-ready Spring Boot guide. Updated for Spring Boot 3.5.x / 4.0.x, Java 17+ (optimized for 21+).

What's New in v2.0

  • Java Records as DTOs (immutable by default)
  • Virtual Threads for high-concurrency I/O (spring.threads.virtual.enabled=true)
  • ProblemDetail (RFC 7807) for standardized error responses
  • RestClient replaces RestTemplate (fluent, synchronous)
  • Structured Logging built into Spring Boot 3.4+
  • Testcontainers as primary integration testing strategy (replaces H2)
  • Observability with Micrometer Observation API
  • Docker Compose integration for dev environments
  • Sealed classes for exception hierarchies
  • GraalVM Native Image / CDS awareness

Quick Start Checklist

  • ✅ Java 17+ (21+ for Virtual Threads)
  • spring-boot-starter-parent for dependency management
  • ✅ Constructor injection with @RequiredArgsConstructor
  • Java Records for DTOs (not mutable @Data classes)
  • ✅ Controllers = routing only; Services = business logic
  • ✅ ProblemDetail (RFC 7807) + @RestControllerAdvice
  • @Valid + Bean Validation on record components
  • ✅ SLF4J {} placeholders + structured logging
  • ✅ YAML profiles (dev/prod/test)
  • ✅ Unit tests (Mockito) + Integration tests (Testcontainers)
  • spring.threads.virtual.enabled=true

Core Architecture

controller/   → HTTP routing only (thin)
    ↓
service/      → Business logic, caching, validation
    ↓
repository/   → Spring Data JPA
    ↓
entity/       → JPA domain models

Each layer depends only on layers below. Controllers never access repositories directly. See architecture.md for layer-based vs feature-based patterns.

Dependency Injection (Constructor Only)

@Service
@RequiredArgsConstructor
public class ProductService {
    private final ProductRepository repository;
    private final ProductMapper mapper;
}

Java Records as DTOs

Records replace @Data Lombok classes: immutable, concise, thread-safe.

Read the full file on GitHub · 410 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 410 lines · 104 tokens per session scan A c90d42bc2991

Subscribe to this mod's changes

java-spring-best-practices is a skill published in the GitHub repository cosbort/agent-skills (6 stars, last pushed 1mo ago), licensed MIT. It adds 104 tokens to every session and 2,897 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories