Generating Spring RESTController Templates #30078
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature: Add Spring Boot REST Controller Generator (spring-controller)
Summary
This PR introduces a new Yeoman sub-generator named spring-controller that allows users to scaffold a basic Spring Boot REST controller with minimal input.
Features
Prompts the user for:
Java package name (e.g., com.example.app)
Controller class name (e.g., GreetingController)
Base endpoint (e.g., /api/greeting)
HTTP method (GET, POST, PUT, DELETE)
Java method name (e.g., sayHello)
Generates a complete controller in the appropriate directory structure:
src/main/java//web/rest/.java
Automatically formats the correct Spring annotation:
@GetMapping, @PostMapping, etc.
Simple and clean generated output:
@RestController
@RequestMapping("/api/greeting")
public class GreetingController {
}
Manual Testing
Verified on a fresh JHipster monolith project
Output controller compiles and runs successfully
Prompts behave as expected
File Structure
Added in:
generators/spring-controller/
├── index.js
└── templates/
└── Controller.java.ejs
Future Improvements
Support method parameters (@RequestBody, @PathVariable)
Add unit test scaffolding
Integrate with service layer
Add automated tests for the generator
Why This Is Useful
This generator speeds up development by automating the creation of REST endpoints — especially helpful for beginners and rapid prototyping.