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.
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rulesWrote 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.
[](https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/java)<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/java"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/java/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/java"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/java.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00000 | $0.02917 |
| Opus 5.5 | $0.00000 | $0.01167 |
| Sonnet 5.5 | $0.00000 | $0.00583 |
| Haiku 4.5 | $0.00000 | $0.00292 |
Grade A, and why
java 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 1mo 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.
How it starts
The opening of the file, as written. The whole thing — 429 lines — stays where its author put it; the contents beside it link to each section on GitHub.
📜 Java 开发规则
版本: v4.3.0 | 最后更新: 2026-01-22 | 作者: Cursor AI Rules
🎯 适用场景
- Spring Boot 微服务开发
- 企业级 Java 应用
- Android 应用开发
- 大数据处理应用
🏗️ 架构原则
面向对象设计
- SOLID 原则: 单一职责、开闭原则、里氏替换、接口隔离、依赖倒置
- 设计模式: 在适当场景使用 GoF 设计模式
- 组合优于继承: 优先使用组合而不是继承
分层架构
- 表现层: Controller/REST API
- 业务层: Service/业务逻辑
- 数据访问层: Repository/DAO
- 领域层: Domain Model/业务实体
📝 编码规范
命名约定
// ✅ 推荐 - 类和接口
public class UserService {
private UserRepository userRepository;
}
public interface PaymentProcessor {
void process(PaymentRequest request);
}
// ✅ 推荐 - 方法和变量
public UserProfile getUserProfile(String userId) {
Optional<User> user = userRepository.findById(userId);
return user.map(this::convertToProfile).orElse(null);
}
private UserProfile convertToProfile(User user) {
// 转换逻辑
}
// ❌ 避免
public class userservice { // 类名应 PascalCase
private UserRepository userrepository; // 变量名应 camelCase
}
public UserProfile GetUserProfile(String userid) { // 方法名应 camelCase
// ...
}
包结构组织
com.company.project
├── api/ # REST API 接口
├── config/ # 配置类
├── domain/ # 领域模型
│ ├── entity/ # JPA 实体
│ ├── repository/# 数据访问接口
│ └── service/ # 业务服务
├── infrastructure/# 基础设施层
│ ├── persistence/# 数据持久化
│ ├── messaging/ # 消息处理
│ └── external/ # 外部服务集成
├── application/ # 应用服务层
└── common/ # 公共组件
├── exception/ # 异常处理
├── util/ # 工具类
└── validation/# 验证器
🔧 最佳实践
异常处理
// ✅ 推荐 - 自定义异常和统一处理
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException ex) {
return ResponseEntity.badRequest()
.body(new ErrorResponse(ex.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
log.error("Unexpected error", ex);
return ResponseEntity.internalServerError()
.body(new ErrorResponse("Internal server error"));
}
}
// 自定义业务异常
public class BusinessException extends RuntimeException {
public BusinessException(String message) {
super(message);
}
}
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.
- 1mo ago First seen · 429 lines · 0 tokens per session scan A 1fb59a068cdd
java is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (17 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,917 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-30.
Other cursor rules, from other repositories
java-import-fqn
A Java code rule that requires using imports and short class names when class names do not conflict. Fully qualified names remain allowed for documented exceptions such as naming conflicts and certain strings.
gradle
Enforce modern Gradle build practices for Java and Android projects, focusing on Kotlin DSL, modularity, version catalogs, and performance optimizations.
mockito
This guide provides definitive best practices for writing robust, maintainable, and readable unit tests using Mockito with JUnit 5, focusing on modern patterns and common pitfalls.
springboot-jpa-best-practices
A set of Chinese-language rules for structuring Java Spring Boot applications that use JPA, a library for database access.
graftcode-java
Mandatory Graftcode architecture rules for building Java backend services (plain Maven/Gradle modules exposed via Graftcode Gateway, not REST).
component-parameter-key-no-dot
A naming rule for Java code parameters marked with @ComponentParameter. Their keys must be flat names using letters, numbers, and underscores; dots are not allowed.