Cursor sometimes suggests JSP templates, XML-based Spring configuration, and other legacy Java patterns because its training data includes older codebases. By adding a .cursor/rules/ file that specifies your Spring Boot version and modern conventions, referencing your existing code with @file, and prompting with framework-specific context, you can ensure Cursor generates code using Spring Boot 3, REST controllers, and annotation-based configuration.
Why Cursor suggests outdated framework patterns and how to fix it
AI code generators are trained on vast codebases that include legacy code from every era of Java development. Cursor may generate JSP views, XML bean definitions, or deprecated Spring APIs simply because those patterns appear frequently in its training data. This tutorial shows you how to anchor Cursor to your specific framework version and coding conventions so it produces modern, annotation-driven Spring Boot code.
Prerequisites
- Cursor installed with a Spring Boot project open
- Spring Boot 3.x with Java 17+ or Kotlin
- Basic understanding of Spring Boot conventions
- Familiarity with Cursor Chat (Cmd+L) and project rules
Step-by-step guide
Create a Spring Boot conventions rule
Create a Spring Boot conventions rule
Add a project rule that specifies your exact Spring Boot version, Java version, and architectural patterns. Be explicit about which legacy patterns are forbidden. The more version-specific your rules, the less likely Cursor is to suggest outdated code.
1---2description: Spring Boot 3.x modern conventions3globs: "*.java,*.kt"4alwaysApply: true5---67# Spring Boot Project Rules8- Project uses Spring Boot 3.2, Java 21, Gradle9- NEVER use JSP, Thymeleaf, or server-side templating10- NEVER use XML-based Spring configuration11- NEVER use WebMvcConfigurerAdapter (removed in Spring 6)12- NEVER use javax.* imports (use jakarta.* instead)13- ALWAYS use @RestController for API endpoints14- ALWAYS use constructor injection (never @Autowired on fields)15- ALWAYS use records for DTOs16- ALWAYS use Spring Data JPA repositories17- Use @Validated and Jakarta Bean Validation for input18- Use ResponseEntity for consistent API responses19- Use @ExceptionHandler with @ControllerAdvice for error handling20- Return JSON responses, not HTML viewsExpected result: Cursor generates modern Spring Boot 3.x code with annotation-based configuration and REST controllers.
Reference your build file for version context
Reference your build file for version context
When prompting Cursor, reference your build.gradle or pom.xml with @file. This gives Cursor concrete version numbers for every dependency, reducing the chance of it suggesting APIs from incompatible versions.
1@spring-boot.mdc @build.gradle23Create a REST API for managing products with these endpoints:4- GET /api/products (list with pagination)5- GET /api/products/{id} (single product)6- POST /api/products (create)7- PUT /api/products/{id} (update)8- DELETE /api/products/{id} (delete)910Use a @RestController, Spring Data JPA repository,11record DTOs, and proper validation. Follow Spring Boot 3.2 patterns.Pro tip: Reference @build.gradle or @pom.xml in every prompt. Cursor reads dependency versions and adjusts its suggestions accordingly, avoiding APIs that were removed or changed between major versions.
Expected result: Cursor generates a ProductController with @RestController, ProductRepository extending JpaRepository, and record-based DTOs with jakarta.validation annotations.
Use @docs to anchor Cursor to current documentation
Use @docs to anchor Cursor to current documentation
Add the Spring Boot 3.x documentation URL to Cursor's indexed docs. This gives Cursor access to current API references when generating code. Open Cursor Settings, find the Docs section, and add the Spring Boot reference URL. Then reference it in prompts with @docs.
1@docs Spring Boot Reference @spring-boot.mdc23Generate a GlobalExceptionHandler using @ControllerAdvice that handles:41. MethodArgumentNotValidException (validation errors) -> 40052. EntityNotFoundException (custom) -> 40463. DataIntegrityViolationException -> 40974. Generic Exception -> 50089Return a consistent ErrorResponse record with timestamp, status,10message, and path fields. Use ProblemDetail from Spring 6.Expected result: Cursor generates a @ControllerAdvice class using Spring 6 ProblemDetail and jakarta imports, not legacy javax or SimpleMappingExceptionResolver.
Refactor legacy-style output with Cmd+K
Refactor legacy-style output with Cmd+K
If Cursor generates code with legacy patterns despite your rules, select the offending code and use Cmd+K to modernize it. This is faster than re-prompting the entire generation and teaches you which patterns Cursor tends to fall back on.
1Refactor this to Spring Boot 3.2 patterns:2- Replace javax.* imports with jakarta.*3- Replace @Autowired field injection with constructor injection4- Replace class DTOs with Java records5- Replace WebMvcConfigurerAdapter with WebMvcConfigurer6- Remove any XML configuration references7- Use ResponseEntity instead of returning plain objectsExpected result: The selected code is updated to use modern Spring Boot 3 patterns with jakarta imports and constructor injection.
Verify output against your project structure
Verify output against your project structure
After generating code, use Cursor Chat to verify it follows your project structure. Reference your existing source directory with @folder so Cursor can see your package naming, layer organization, and existing patterns.
1@spring-boot.mdc @src/main/java/com/example/23Review the generated ProductController and ProductService.4Check that they follow the same patterns as existing controllers5in this project. Flag any inconsistencies with:61. Package naming conventions72. Method naming conventions83. Exception handling patterns94. DTO naming and structure105. Repository method namingExpected result: Cursor identifies any inconsistencies between the generated code and existing project patterns, suggesting corrections.
Complete working example
1---2description: Spring Boot 3.x modern conventions3globs: "*.java,*.kt"4alwaysApply: true5---67# Spring Boot Project Rules8- Project uses Spring Boot 3.2, Java 21, Gradle9- NEVER use JSP, Thymeleaf, or server-side templating10- NEVER use XML-based Spring configuration11- NEVER use WebMvcConfigurerAdapter (removed in Spring 6)12- NEVER use javax.* imports (use jakarta.* instead)13- NEVER use @Autowired on fields (constructor injection only)14- ALWAYS use @RestController for API endpoints15- ALWAYS use constructor injection via final fields16- ALWAYS use Java records for DTOs and value objects17- ALWAYS use Spring Data JPA repositories18- Use @Validated and Jakarta Bean Validation19- Use ResponseEntity for API responses20- Use @ControllerAdvice with @ExceptionHandler21- Use ProblemDetail (RFC 7807) for error responses2223# Package Structure:24- controller/ — REST controllers25- service/ — Business logic26- repository/ — Data access (JPA)27- model/ — Entities28- dto/ — Request/response records29- config/ — Configuration classes30- exception/ — Custom exceptions and handlers3132# Example Controller Pattern:33```java34@RestController35@RequestMapping("/api/products")36@RequiredArgsConstructor37public class ProductController {38 private final ProductService productService;3940 @GetMapping41 public ResponseEntity<Page<ProductResponse>> list(Pageable pageable) {42 return ResponseEntity.ok(productService.findAll(pageable));43 }44}45```Common mistakes
Why it's a problem: Not specifying the exact Spring Boot and Java version in rules
How to avoid: Always include exact version numbers: 'Spring Boot 3.2, Java 21' in your project rules.
Why it's a problem: Asking Cursor to generate Spring code without referencing build.gradle
How to avoid: Always reference @build.gradle or @pom.xml so Cursor sees your actual dependency versions.
Why it's a problem: Accepting generated code without checking import statements
How to avoid: Check imports first. If you see javax.persistence or javax.validation, Cursor generated Spring Boot 2 code. Use Cmd+K to fix imports.
Best practices
- Specify exact framework and language versions in every .cursor/rules/ file
- Reference @build.gradle or @pom.xml in prompts for accurate dependency context
- Add Spring Boot documentation via @docs for up-to-date API references
- Use Cmd+K to quickly fix legacy patterns in generated code
- Include example code patterns in rules so Cursor matches your style exactly
- Start fresh Chat sessions when Cursor reverts to legacy patterns mid-conversation
- Review generated import statements first since they reveal version mismatches immediately
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a Spring Boot 3.2 project using Java 21. Generate a REST controller for user management with CRUD endpoints, constructor injection, record DTOs, Jakarta validation, and ProblemDetail error responses. Do not use any deprecated or legacy Spring patterns.
@spring-boot.mdc @build.gradle Create a complete OrderService with @Service annotation, constructor injection, Spring Data JPA repository calls, proper exception handling with custom exceptions, and record-based DTOs. Follow Spring Boot 3.2 conventions exactly.
Frequently asked questions
Why does Cursor suggest JSP when my project has no views?
Cursor's training data includes millions of Spring MVC projects that use JSP. Without explicit rules stating you are building a REST API, Cursor may default to full-stack patterns including view templates.
Can I use @docs with Spring Boot reference documentation?
Yes. Add the Spring Boot 3.x reference URL in Cursor Settings under Docs. Then use @docs Spring Boot in your prompts for current API references.
How do I stop Cursor from using @Autowired on fields?
Add 'NEVER use @Autowired on fields. ALWAYS use constructor injection via final fields and @RequiredArgsConstructor' to your rules. Include an example showing the correct pattern.
Does this approach work for other frameworks like Django or Rails?
Yes. The same technique applies to any framework: specify the exact version, list forbidden legacy patterns, provide correct pattern examples, and reference your project configuration file.
What if I need to maintain a legacy Spring Boot 2 project?
Create rules that specify Spring Boot 2.x with javax imports. The key is version specificity. Cursor can generate code for any version when explicitly told which one to target.
Can RapidDev help modernize our Spring Boot project?
Yes. RapidDev helps teams migrate from Spring Boot 2 to 3, configure Cursor for Java development, and establish modern patterns across the codebase.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation