Quick Start
1. Add dependencies
Section titled “1. Add dependencies”Follow the Installation guide to add sprout-annotations and
sprout-processor to your project.
2. Annotate your entity
Section titled “2. Annotate your entity”import de.flix29.sprout.annotations.SproutResource;import jakarta.persistence.Entity;import jakarta.persistence.Id;
@Entity@SproutResourcepublic class Book { @Id private Long id; private String title; private String author;
// getters / setters ...}@SproutResource with no attributes uses all defaults:
- Resource name:
Book(the class name) - Base path:
/api/books(lowercase +s) - All five CRUD endpoints are generated
3. Build
Section titled “3. Build”mvn clean package# or./gradlew buildDuring compilation you will see Sprout’s log output prefixed with [Sprout]:
[Sprout] Processing: com.example.domain.Book[Sprout] Resolved ID: field 'id' (type: java.lang.Long)[Sprout] Base API path: /api/books[Sprout] Generating: SproutBookController, SproutBookService, ...Generated sources land at:
target/generated-sources/annotations/com/example/domain/generated/├── controllers/SproutBookController.java├── services/SproutBookOperations.java├── services/SproutBookService.java├── repositories/SproutBookRepository.java└── marker/SproutBookMarker.java4. Run and test
Section titled “4. Run and test”Start your Spring Boot application. The generated controller is a standard @RestController,
picked up by component scanning as long as your @SpringBootApplication covers the entity’s
package (or a parent package).
# List all bookscurl http://localhost:8080/api/books
# Create a bookcurl -X POST http://localhost:8080/api/books \ -H "Content-Type: application/json" \ -d '{"title":"Clean Code","author":"Robert C. Martin"}'
# Get by IDcurl http://localhost:8080/api/books/1
# Updatecurl -X PUT http://localhost:8080/api/books/1 \ -H "Content-Type: application/json" \ -d '{"title":"Clean Code (2nd Ed.)","author":"Robert C. Martin"}'
# Deletecurl -X DELETE http://localhost:8080/api/books/1Next steps
Section titled “Next steps”- Annotations reference — learn all
@SproutResourceoptions - Customization — override service logic for your entity
- Security Policies — add
@PreAuthorizeper endpoint