r/SpringBoot • u/Bariss26 • Jun 10 '26
Discussion I got tired of writing the same Spring Boot CRUD boilerplate, so I built a deterministic compile-time generator.
In every Spring Boot project, we end up writing the exact same layers for basic CRUD: Read/Create/Update DTOs, MapStruct interfaces, REST Controllers, Services, and Repositories.
AI can generate this, but it doesn't enforce a stable contract across a codebase. Runtime solutions (like Spring Data REST) add reflection overhead, limit custom business logic, and bloat JSON payloads with HATEOAS _links.
I wanted a solution that generates plain, reviewable Java source code during the build phase (javac), with zero runtime dependencies. So, I wrote an annotation processor.
You just annotate your JPA entity:
@CrudGen
@Entity
public class Product {
@Id @GeneratedValue
private Long id;
@DtoField(dto = "Create", required = true)
@DtoField(dto = "Update")
@DtoField(dto = "Read")
private String name;
@DtoField(dto = "Read")
private BigDecimal price;
}At compile time, it automatically generates the build/generated sources for:
- Controllers & Services: Configurable endpoints for CRUD, batch operations, and pagination.
- Clean DTOs & Mappers: Generates the POJOs and the MapStruct interfaces.
- JSON Patch: Native support for
application/json-patch+jsonpartial updates. - N+1 Safe Queries: Automatically applies
@EntityGraphon JPA reads to handle relations without mapper-level database lookups.
The generated code is part of your normal build output. Failures surface at compile time, and changes are visible in diffs. The library targets Spring Boot 3 and 4 (processor runs on Java 8+).
I would love to get your architectural feedback on the compile-time generation approach vs. runtime reflection tools.
(Links to the repo and Maven Central are in the comments).
9
u/edzorg Jun 11 '26
The problem for me at least is that I want the source code in my repo, editable, versioned. If I were to use this I would annotate, build, remove the annotation and copy all the generated code into src/.
In a world of AI agents having more code and less magic is a good thing. I want my AI to have access to all that boilerplate to understand and modify my application. An AI cannot well handle a little known annotation that deliberately abstracts away a lot of the code.
3
u/Bariss26 Jun 10 '26
GitHub: https://github.com/bariskokulu/CRUDGen
Maven Central: io.github.bariskokulu:crudgen:1.1.0
4
u/Distinct-Speaker5435 Jun 11 '26
I think this compile-time code generation magic will have a harder time than ever. People don’t want to write the boilerplate code, true. But why should I include such a project which creates another dependency and needs maintenance by the author if any AI agent can write the controllers etc. The models all do understand Spring (Boot) extremely well due to all the training. So every refactoring will be easy, even with other models. And I don’t need humans to understand your specific annotations, I just need a human reviewer who understands Spring.
I
1
u/Historical_Ad4384 Jun 11 '26
I can just use Claude to generate any boilerplate
1
u/NiklasEldberger Jun 24 '26
I have the same experience of writing to much boiler plate for the standard CRUD use cases for every customer. My approach is different from yours though (and still no AI...), I just have the OpenAPI-definition with a few custom extensions to declare the full implementation of the vanilla CRUD that I otherwise need to code over and over again. Any custom controllers in my Spring boot application will take precedence. Putting things from different projects I have done in the past into this lib (dcentb - Data CENTric Backend) and so far I get the following:
I had claude code create a demo CRUD API using the dcentb lib and tell me the pros and cons so far, this is the verdict: https://github.com/niklase/lets-build-apis/tree/main/dcentb-todo-demo
Maybe that would solve your CRUD boilerplate issues? And still without any AI involved. Work in progress...
1
u/Aromatic_Ad3754 Jul 29 '26
You can use Spring Data Rest
1
u/alfespa17 Jun 11 '26
You can try using elide
https://github.com/yahoo/elide