spring-boot

A set of coding rules for Spring Boot, a Java framework for building web services and applications. It covers controllers, business services, database access with JPA, validation, dependency injection, and data-transfer objects.

In plain words
What is it for?
Use it when building or reviewing Spring Boot REST endpoints, service layers, repositories, DTOs, validation, pagination, and JPA database code.
Why use it?
It keeps application layers separate and helps prevent invalid API input, exposed database entities, inconsistent status responses, and difficult-to-test dependencies.

Cursor rule

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 rules/nedcodes-ok/cursorrules-collection/spring-boot
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection
Per session 478 This file is loaded in full into every session.
When invoked 478 The same file — it is already loaded in full.
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.00478 $0.00478
Opus 5 $0.00239 $0.00239
Sonnet 5 $0.00096 $0.00096
Haiku 4.5 $0.00048 $0.00048

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

Security

Grade A, and why

spring-boot 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 yesterday.

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.

rules-mdc/frameworks/spring-boot.mdc · 46 lines

How it starts

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

Spring Boot Cursor Rules

You are an expert Spring Boot developer. Follow these rules:

Architecture

  • Layer separation: Controller → Service → Repository. No cross-layer skipping
  • One @RestController per resource. Keep endpoint count under 8 per controller
  • Constructor injection only. No @Autowired on fields — use final fields with @RequiredArgsConstructor
  • Use @Service for business logic, @Repository for data access. Never put logic in controllers

REST Controllers

  • Use @GetMapping, @PostMapping etc. — never raw @RequestMapping with method parameter
  • Return ResponseEntity with explicit status codes. No void controller methods
  • @Valid on all @RequestBody parameters. DTO validation via Jakarta annotations
  • Pageable for list endpoints: return Page, not List

DTOs & Mapping

  • Separate Request, Response, and Entity classes. Never expose entities in API responses
  • Use records for DTOs in Java 17+. Immutable by default
  • MapStruct for entity-DTO mapping. No manual mapping in services
  • Validate with @NotNull, @Size, @Pattern — custom validators for business rules

JPA & Data

  • Spring Data JPA repositories with derived query methods. @Query for complex queries
  • Always use @Transactional on service methods that write. Read-only: @Transactional(readOnly = true)
  • Fetch strategy: LAZY by default. Use @EntityGraph or JOIN FETCH for N+1 prevention
  • Flyway or Liquibase for migrations. Never spring.jpa.hibernate.ddl-auto=update in production

Error Handling

  • @RestControllerAdvice with @ExceptionHandler for global error handling
  • Custom exception hierarchy: BusinessException → specific exceptions
  • Return ProblemDetail (RFC 7807) for all error responses
  • Log exceptions at service layer, not controller layer

Configuration

  • application.yml over .properties. Profile-specific files: application-{profile}.yml
  • @ConfigurationProperties for grouped config, not scattered @Value annotations
  • Externalize all secrets. Use Spring Cloud Config or environment variables
  • Health checks via Spring Actuator. Expose only /health and /info in production

Read the full file on GitHub · 46 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. yesterday First seen · 46 lines · 478 tokens per session scan A 4d6a849be32a

Subscribe to this mod's changes

spring-boot is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 478 tokens to every session, about $0.0024 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-30.