cursorrules

A set of coding rules for Java and Spring Boot projects. Spring Boot is a Java framework for building web services and other applications.

In plain words
What is it for?
Use it when creating or reviewing Spring Boot controllers, services, repositories, models, configuration, REST APIs, validation, database access, caching, asynchronous work, and tests.
Why use it?
It gives an agent consistent expectations for project structure, naming, configuration, dependency injection, error handling, testing, and performance.

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/ladliulivecn/cursor-rules/cursorrules
Clone the repo
git clone --depth 1 https://github.com/ladliulivecn/cursor-rules

Made for: Cursor.

Per session 775 This file is loaded in full into every session.
When invoked 775 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.00775 $0.00775
Opus 5 $0.00387 $0.00387
Sonnet 5 $0.00155 $0.00155
Haiku 4.5 $0.00077 $0.00077

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

Security

Grade A, and why

cursorrules 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.

java_spring/.cursorrules · 90 lines

What it actually says

代码风格和结构

  • 编写干净、高效且文档齐全的Java代码,并附上准确的Spring Boot示例。
  • 在代码中使用Spring Boot的最佳实践和约定。
  • 创建Web服务时,遵循RESTful API设计模式。
  • 使用描述性的变量和方法名,遵循驼峰命名法。
  • 结构化Spring Boot应用:控制器(controllers)、服务(services)、仓库(repositories)、模型(models)、配置(configurations)。

Spring Boot 特定要求

  • 使用Spring Boot Starters进行快速项目设置和依赖管理。
  • 正确使用注解(例如:@SpringBootApplication, @RestController, @Service)。
  • 有效利用Spring Boot的自动配置功能。
  • 使用@ControllerAdvice和@ExceptionHandler实现正确的异常处理。

命名约定

  • 类名使用帕斯卡命名法(例如:UserController, OrderService)。
  • 方法和变量名使用驼峰命名法(例如:findUserById, isOrderValid)。
  • 常量使用全大写命名(例如:MAX_RETRY_ATTEMPTS, DEFAULT_PAGE_SIZE)。

Java 和 Spring Boot 使用

  • 在适用时使用Java 17或更高版本的特性(例如:records, sealed classes, pattern matching)。
  • 利用Spring Boot 3.x的特性和最佳实践。
  • 对数据库操作使用Spring Data JPA。
  • 使用Bean Validation(例如:@Valid, 自定义验证器)实现正确的验证。

配置和属性

  • 使用application.properties或application.yml进行配置。
  • 使用Spring Profiles实现环境特定的配置。
  • 使用@ConfigurationProperties实现类型安全的配置属性。

依赖注入和IoC

  • 优先使用构造器注入而非字段注入以提高可测试性。
  • 利用Spring的IoC容器管理bean生命周期。

测试

  • 使用JUnit 5和Spring Boot Test编写单元测试。
  • 使用MockMvc测试Web层。
  • 使用@SpringBootTest实现集成测试。
  • 对仓库层测试使用@DataJpaTest。

性能和可扩展性

  • 使用Spring Cache抽象实现缓存策略。
  • 使用@Async进行异步处理,实现非阻塞操作。
  • 实现正确的数据库索引和查询优化。

安全

  • 使用Spring Security进行认证和授权。
  • 使用正确的密码编码(例如:BCrypt)。
  • 在需要时实现CORS配置。

日志和监控

  • 使用SLF4J和Logback进行日志记录。
  • 实现正确的日志级别(ERROR, WARN, INFO, DEBUG)。
  • 使用Spring Boot Actuator进行应用监控和指标收集。

API 文档

  • 使用Springdoc OpenAPI(前称Swagger)生成API文档。

数据访问和ORM

  • 对数据库操作使用Spring Data JPA。
  • 实现正确的实体关系和级联操作。
  • 使用Flyway或Liquibase进行数据库迁移。

构建和部署

  • 使用Maven进行依赖管理和构建过程。
  • 为不同环境(开发、测试、生产)实现正确的配置。
  • 在适用时使用Docker进行容器化。

遵循最佳实践

  • 遵循RESTful API设计(正确使用HTTP方法、状态码等)。
  • 若适用,采用微服务架构。
  • 使用Spring的@Async或Spring WebFlux进行异步处理。

遵循SOLID原则,保持Spring Boot应用设计中的高内聚和低耦合。


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 · 90 lines · 775 tokens per session scan A 225514be585a

Subscribe to this mod's changes

cursorrules is a cursor rule published in the GitHub repository ladliulivecn/cursor-rules (13 stars, last pushed 1y ago), licensed MIT. It adds 775 tokens to every session, about $0.0039 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.