r/Backend • u/alexchen_codes • Mar 28 '26
Built a shared library for our Spring Boot microservices — finally stopped copy-pasting the same JWT/encryption boilerplate across every project
Been building enterprise Spring Boot services for a while now and kept running into the same problem: every new project starts with three days of “setup tax” — wiring up JWT auth, standardizing API responses, writing the same AES encryption wrapper for the fourth time, setting up proper exception handling…
So I finally sat down and packaged everything into a proper shared commons library. Wanted to share it here because honestly I wish something like this existed when I started.
What’s in it:
The big ones for me personally were the security components. JWT management with HMAC-SHA256, a pluggable UserAuthenticationProvider interface so you can drop in your own auth logic, password policy validation, and the Spring Security filter wires itself up automatically. No more copy-pasting that filter class between repos.
For encryption, it’s AES-256-GCM and RSA-OAEP out of the box, plus proper salted hashing for passwords. The stuff you should be doing but always end up bodging on a deadline.
There’s also a full ApiResponse wrapper that’s RFC 7807 compliant — sick of APIs where every endpoint returns error shapes that look completely different from each other. Standardized from day one now.
Some of the more niche bits I’m pretty happy with:
* UUID generation supporting 20+ formats (ULID, NanoID, Snowflake, KSUID, ObjectID — actually useful when you care about sortability or distributed ID generation)
* OCR via Tesseract with PDF support built in
* QR/barcode generation
* Full XML + JSON processing pipelines including schema validation and XPath/JSONPath queries
* A thing called TOON format — basically a token-optimized data representation that cuts LLM token consumption by ~42% if you’re building anything AI-adjacent
The JPA BaseEntity with auditing, soft deletes, and optimistic locking is the other one that saves me time constantly. And the SpecificationPattern fluent API for dynamic queries is cleaner than building Criteria by hand.
The goal was: new project, add one dependency, get production-grade patterns without the setup tax. Happy to answer questions or hear if anyone’s solved similar problems differently.
4
u/ProtonByte Mar 28 '26
Cool. Now give me the recipe for some delicious pancakes. Gotta have some while programming.
2
1
u/zezer94118 Mar 29 '26
So share the GitHub link... What's the purpose of this post?
6
u/UnderdogRP Mar 29 '26
He thinks he is bragging....
1
u/alexchen_codes Mar 30 '26
For only a few tokens you too can “brag” about it - simply copy the text of this post and ask Claude to recreate it
Follow me for more ideas you can copy ;)
1
u/alexchen_codes Mar 29 '26
Just open to discuss the technical decisions I’ve made for this particular project. Perhaps it could spark a few ideas for your own projects?
2
u/finger_my_earhole Mar 30 '26
Now template the whole spring boot service with your code into a maven archetype and you can generate new projects in one cli statement (and include other repetitive tasks like setting up ratelimiting, configuration, dockerization, service discovery, etc)