spring-boot-java-style

Java coding rules for imports, access levels, dependency injection, constants, annotations, and related source-code structure. They define consistent conventions for Spring projects.

In plain words
What is it for?
Use them when writing or reviewing Java classes, especially Spring services, repositories, controllers, models, and tests.
Why use it?
They reduce style differences and make Java code easier to read, review, and maintain.

Cursor rule for Cursor

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/lsampaioweb/ai-instructions/spring-boot-java-style
Clone the repo
git clone --depth 1 https://github.com/lsampaioweb/ai-instructions

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 556 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.00000 $0.00556
Opus 5 $0.00000 $0.00278
Sonnet 5 $0.00000 $0.00111
Haiku 4.5 $0.00000 $0.00056

Measured yesterday against content hash b18cca2545f0, 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-java-style 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.

.cursor/rules/spring-boot-java-style.mdc · 29 lines

How it starts

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

Java Style Engine

Rules

  • Organize imports in this order: (1) static imports, (2) standard Java imports, (3) Spring and third-party imports, (4) project imports.
  • Import each type explicitly (no wildcard imports).
  • Order class-level annotations in this sequence: logging (e.g., @Slf4j) → stereotype (e.g., @Service, @Repository, @Component) → behavioral (e.g., @Transactional, @Validated).
  • Use Java records for immutable value types only when no component-specific rule applies; *Model, *Request, and *Response follow their component engines.
  • Declare every type member (field, method, constructor, nested type) with the most restrictive visibility that satisfies its usage scope; default to private and expand only when external access is required.
  • Extract repeated string literals—including message-resolution keys passed to ApiException, logMessages.get(), or equivalent, and literals reused across test methods—into named private static final String constants in UPPER_SNAKE_CASE in the owning class, unless a more specific rule grants an explicit exception.
  • Use constructor injection as the only dependency injection pattern.
  • Validate required constructor parameters with Objects.requireNonNull in non-record classes.
  • Order methods within a class in this sequence: constructors → public methods → package-private methods → private helpers.
  • Annotate every method that overrides a superclass or interface method with @Override.
  • Add one blank line before return in any method body that contains at least one preceding statement.
  • Omit the blank line before return when the method body is a single return statement.
  • Use var only when the inferred type is unambiguous from the right-hand side of the assignment.
  • Use the ternary operator only for single-expression assignments.
  • Extract multi-statement logic, complex boolean conditions, and collection constructions into named private helpers; keep callers at a higher abstraction and name helpers by intent (e.g., getSupportedLocales(), not buildLocaleList(); avoid generic prefixes such as build, compute, or process when a domain-specific name is available).
  • Keep public and package-private methods intent-revealing; declare same-class-only helpers private.

Read the full file on GitHub · 29 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 · 29 lines · 0 tokens per session scan A b18cca2545f0

Subscribe to this mod's changes

spring-boot-java-style is a cursor rule published in the GitHub repository lsampaioweb/ai-instructions (1 stars, last pushed 9d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 556 tokens. 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.