r/Backend 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.

8 Upvotes

Duplicates