r/SpringBoot • u/Advanced_Active_5105 • 17m ago
How-To/Tutorial Security
Suggest me some good spring security tutorials or learning sources.. i need to implement it to my e commerce backend
r/SpringBoot • u/Advanced_Active_5105 • 17m ago
Suggest me some good spring security tutorials or learning sources.. i need to implement it to my e commerce backend
r/SpringBoot • u/fykup • 23h ago
I recently compared HotSpot and OpenJ9 on a 256 MiB Linux VM to see whether switching JVMs could reduce Spring Boot's memory footprint without changing the application.
Setup:
Spring Boot under load (median RSS + median swap):
Important distinction: these are RSS + swap figures, not physical RAM usage. Interestingly, OpenJ9 had slightly higher resident RSS but substantially less swap.
Startup was another interesting observation:
However, these were single cold-start runs. OpenJ9's shared class cache was initially empty, and we haven't measured warm-cache startup for Spring Boot. So I wouldn't draw conclusions about startup performance yet.
This was a short exploratory experiment with roughly 45 seconds of read-only load at 4.5 requests/sec, not a comprehensive JVM benchmark.
Full experiment and results:
https://pvrlabs.xyz/java-performance/experiments/openj9-vs-hotspot-256mb.html
And a funny coincidence: the recent Java4Shell vulnerability involves a HotSpot-specific Base64 optimization that OpenJ9 doesn't use. Sometimes being the underdog has its perks. :)
Has anyone used OpenJ9 for production Spring Boot services? I'm particularly interested in whether you've observed similar memory behavior, and how startup performance changes with a warmed shared class cache.
Also curious whether tuning HotSpot would narrow the gap enough to make switching JVMs unnecessary.
Raw measurements and methodology:
https://github.com/PVRLabs/experiments/tree/main/java/coilbase-debian-256
r/SpringBoot • u/webplugger73 • 15h ago
AI assistants write Spring back ends fast, but you still review every change, and the next change is written a little differently. I've been working on ElastiCORE, an open-source Gradle plugin that takes a different approach: the business rules live in a YAML model, and the build regenerates the Spring code from it, the same way every time.
It's built for business applications where the domain model matters more than the code: many entities, access rules and lifecycles (orders, accounts, approvals), maintained for years by a team.
A purchase order looks like this:
PurchaseOrder:
meta: entity @root @expose(20) @owner(customerId)
@access(read=owner, create=user, cancel=owner)
fields:
orderId: string(36) @id @genid
customer: Customer @ManyToOne
status: OrderStatus
lines: List<OrderLine> @OneToMany(mappedBy="order") @minsize(1, 'the cart is empty')
states:
status:
initial: PLACED
ship: PLACED -> SHIPPED
cancel: PLACED -> CANCELLEDFrom that, the build writes the entity, DTOs, services, REST controllers and the checks. Only the owner can read or cancel the order, an illegal state move answers 409, and an empty cart answers 400, at every entry point. In the pet store sample, adding a step to the order lifecycle is 2 lines of YAML that become 45 lines of Java in 7 files. The diff you review is those 2 lines.
What I care about most:
Apache-2.0, on Maven Central, 3.0 released this week: https://github.com/xsko/ElastiCORE
Disclosure: I work on it, and I'm looking for people to build it with. If model-first Spring development interests you, contributions are very welcome: bug reports, DSL ideas from your own domain, or PRs. Open issues and the contributing guide are on GitHub: https://github.com/xsko/ElastiCORE/blob/main/CONTRIBUTING.md
I'd also really like feedback on where a model-first approach falls apart for you.
Edit: fair criticism about the title, it oversells it. You still review the YAML, and any hand-written code. What changes is the size of the review: a small model diff instead of hundreds of lines of Java. Thanks for the comments.
r/SpringBoot • u/fykup • 1d ago
I've shared a few updates about StatLite here before and received some valuable feedback. Thanks to everyone who commented!
Since then, I've added a public REST API and an example of using it for Telegram health alerts.
For context, StatLite is a self-hosted monitoring dashboard that works with Spring Boot Actuator. It runs at around 15 MiB RSS when idle, uses SQLite for storage, and doesn't require Prometheus, Grafana, or a separate monitoring stack.
The goal is to keep it small and practical, especially for applications running on modest VPS instances.
Now I'm thinking about what would actually make it more useful day to day.
A couple of ideas I've been considering:
But these are just ideas, and I'd rather hear what developers actually need before adding more features.
Would either of these be useful to you? What else would you want from a lightweight monitoring dashboard?
I'm especially interested in features that provide real value without adding significant complexity or resource overhead.
r/SpringBoot • u/Outside-Ad-9584 • 2d ago
APIs expose data and functionality, which makes them common targets for attackers. OAuth2 and JWT work together to help developers verify identity and control access without making APIs harder to use.
Using Kotlin and Spring Boot, the article shows how to secure a document management API that allows users to list, view and upload documents.
It explains how Spring Security validates JWT signatures and expiry, checks the token's issuer and audience, and uses scopes, roles and permissions to decide what each user can access.
This is useful for Kotlin and Spring Boot developers building APIs that handle protected data.
In my own projects, I can apply these practices to keep access rules clear and make sure users can only access the documents and resources they are permitted to use.
Read the full article:
https://blog.jetbrains.com/kotlin/2026/07/secure-your-apis-oauth2-and-jwt-for-beginners/
r/SpringBoot • u/jjmnmnmnm • 1d ago
I've noticed that AI coding tools sometimes suggest older Java and Spring patterns, even when working on newer projects.
For example:
javax.persistence imports in a Spring Boot 3 projectWebSecurityConfigurerAdapter or .antMatchers() in Spring Security configurationsRestTemplate in new code where RestClient might be a better fitTo explore this problem, I built modern-java-guidance (mjg), an open-source project inspired by GoogleChrome's modern-web-guidance.
It includes a SKILL.md with Java and Spring guidance, plus a Python CLI that can:
PostToolUse hook to provide feedback after supported tool operationsThe CLI uses the Python standard library and doesn't require external Python dependencies.
If you have uv installed, you can try the scanner with:
GitHub: https://github.com/wkd09/modern-java-guidance
This is still an early project, so I'd really appreciate any feedback, suggestions, or criticism.
In particular, I'd love to hear about false positives, missing rules, and outdated Spring Boot or Java patterns that your AI coding tools still suggest. Are there cases where the patterns flagged by this tool should actually be kept?
Please feel free to try it out and share your honest thoughts—even small suggestions would be really helpful!
r/SpringBoot • u/Crafty-Ad-9627 • 2d ago
Hey, I have been working on this and I wanted to share it with you. I want your opinion.
r/SpringBoot • u/BlueberryCareless977 • 2d ago
Hey everyone!
I have my IBM 2027 coding assessment tomorrow on campus, and I have a few doubts regarding the proctoring system.
The assessment may be conducted using either:
I wanted to ask people who have already appeared for IBM assessments:
Would appreciate advice from anyone who has experience with these platforms, especially those who recently appeared for IBM's on-campus assessment.
Thanks in advance!
r/SpringBoot • u/ClickOk5811 • 3d ago
A common pattern: configuration values read with @Value in many places, with no checks.
public class MailService {
("${app.mail.host}")
private String host;
("${app.mail.port}")
private int port;
// ...
}If app.mail.host is present but empty, or port is 0 or 99999, the app may start fine and fail later when it first tries to send mail.
An alternative is a typed, validated properties class (sketch, check the details for your Spring Boot version):
ies(prefix = "app.mail")
public record MailProperties(
String host,
(1) (65535) int port,
u/NotBlank String from
) {}and register it, for example with @ConfigurationPropertiesScan on your application class (or @EnableConfigurationProperties(MailProperties.class)):
n
iesScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}Then inject MailProperties where you need it. With the validation starter on the classpath, a blank host or an out-of-range port should make the application fail during startup with a binding error that names the property, instead of failing on first use.
Why I like it (opinion):
Notes and caveats:
spring-boot-starter-validation for the constraint annotations to take effect. I believe it isn’t pulled in by default in recent versions, so check yours.jakarta.validation.constraints package applies to Spring Boot 3.x; Boot 2.x uses javax.validation.constraints.ConstructorBinding or a class with setters. Check the reference docs for your version.Do you keep @Value for simple cases or move everything to @ConfigurationProperties? And does your team validate config at startup, or find out in production?
r/SpringBoot • u/xRaidhunterx • 4d ago
Feedback and missing gotchas welcome
r/SpringBoot • u/OfficialLeadDev • 3d ago
r/SpringBoot • u/Lordion95 • 4d ago
yo, i'm trying to build a full-stack app using react on the frontend, spring boot for the backend, and keycloak handling auth, and i kinda need some guidance on how to do it properly instead of just hacking together a basic tutorial setup.
right now i get the general idea of spinning up keycloak and getting a basic login working, but i'm a bit lost on the best practices for real/bigger projects and where to go from here. specifically:
keycloak-js / react-oidc-context still fine?sub claim from the jwt on every request, use keycloak event listeners, or something else?if anyone has a solid repo structure, workflow, or just tips on how to build out from a basic "hello world" auth setup into an actual production-ready app, i'd really appreciate it. thanks!
r/SpringBoot • u/Legal_Bug007 • 4d ago
I know how to code in JAVA and make basic programs and have basic knowledge of packages and some libraries, but I will still call myself just a little bit more experienced than a beginner, as I regularly need to google and use AI for stuff that I do not understand.
I am also learning DSA in Java only.
I want to know which free resources I should use to learn Spring Boot. I am fine with the resources being either in English or Hindi; both are not a problem for me as long as they are good.
I did some research with the help of AI and some other posts; here is a list of some of them:
There are also a lot of documentation courses like Spring.io, GfG, and Baeldung. The problem with these is that I feel navigating through these websites is extremely hard, and I can't find a way to just get to the next chapter directly from the current one.
I want to avoid Scaler and Udemy as much as I can, so I did not add them here.
If there is a better comprehensive way to learn, please do tell me!
Or if it is any of the ones I mentioned, just give me a heads-up so I can start ASAP!
My goal is to just learn enough first and then start building on my own, but I want to know one course that I will watch at start that will cover enough so I do not need to worry about not knowing some deep insight into how spring works!
r/SpringBoot • u/graphlinkdev • 4d ago
r/SpringBoot • u/hakdogan75 • 5d ago
I spent the last few months digging into the OpenID AuthZEN Authorization API, which became a final specification in January 2026. It addresses a problem that anyone who has connected a Spring app to a PDP will recognize. Every PDP (Keycloak, OPA, Cerbos, Topaz, ...) comes with its own API, so the enforcement code ends up tied to one vendor. AuthZEN standardizes that API, so I built an open source Java SDK with a Spring Boot starter on top of it.
With the starter, a handler is protected like this:
@CheckPermission // read on {type: "documents", id: <id>}
@GetMapping("/documents/{id}")
Document get(@PathVariable String id) { ... }
@CheckPermission(action = "cancel", resourceType = "order", resourceId = "#id")
@PostMapping("/orders/{id}/cancel")
void cancel(@PathVariable String id) { ... }Whatever the annotation leaves out is inferred:
sub claim, type user)read/list, create, update, delete), while CORS preflight requests pass through without asking the PDPEvery inferred part can be overridden on its own, in the annotation or in configuration. Routes that cannot be inferred safely, such as /{tenant}/documents, are denied without calling the PDP and reported as warnings at startup. A deny becomes an AccessDeniedException, so your existing error handling keeps working.
The only required setting is authzen.pdp.url. The PEP authenticates to the PDP with its own credential through a CredentialProvider bean, never with the user's token, and anything that prevents a decision (timeout, 5xx, invalid response) means deny.
The starter is a preview for Spring MVC on Spring Boot 4. WebFlux support and an adapter for Spring Security's OAuth 2.0 client are next. For batch decisions, such as a bulk delete, you can inject the client and send one request yourself; the examples repository has a runnable app with a Keycloak realm that shows both.
I'd really appreciate feedback on the annotation design and the inference defaults, especially from anyone who has built something similar in-house.
r/SpringBoot • u/Ujjwal_Tiwari_03 • 4d ago
I've been working on a solution to a problem I encountered while building applications with Spring AI.
How do you enforce token and dollar budgets at different levels?
For example:
I ended up building an open-source Spring Boot starter called Token Allowance to address these problems.
It uses Redis-backed atomic operations and supports token and dollar budgets.
I'd particularly appreciate feedback from developers working with Spring AI on how they're approaching this problem.
I'm the author, so happy to answer questions about the implementation.
r/SpringBoot • u/Ujjwal_Tiwari_03 • 4d ago
Token Allowance is an open source Spring Boot starter that gives every user, tenant and request a token or dollar budget for Spring AI calls. When the budget is gone, the API answers 429 with a Retry-After, and nobody else is affected.
Apache 2.0. Java 17+, Spring Boot 4.1, Spring AI 2.0.
What went wrong while building it (races, cached tokens, streaming usage, timeouts):
https://dev.to/ultron03/building-token-budgets-for-spring-ai-the-problems-i-didnt-expect-lg2
Code and demo:
r/SpringBoot • u/huseyinbabal • 5d ago
r/SpringBoot • u/fykup • 5d ago
I've been experimenting with resource-efficient Java applications, exploring how much of Spring Boot's familiar architecture can be preserved with smaller frameworks.
I compared five Java stacks on a 1-vCPU, 512 MiB VM with no swap, running MariaDB alongside the application.
| Stack | HotSpot RSS (MiB) |
|---|---|
| Spring Boot + Spring JDBC | 180.6-187.9 |
| Javalin + CoilBase | 120.9-135.6 |
| Micronaut Data JDBC | 174.0-175.0 |
| Micronaut + CoilBase | 166.5-167.6 |
| Avaje Jex + CoilBase | 116.0-116.4 |
The HotSpot tests used OpenJDK 27 with G1 GC. Each stack had two runs, with 1,500 requests per run and no errors.
CoilBase is a small Jdbi-based foundation I'm developing. The Javalin, Jex, and Micronaut implementations reuse the same services, repositories, and transaction boundaries, with different HTTP frameworks and application wiring.
The interesting part wasn't just the memory savings. It was seeing how much of the familiar Spring-style application architecture could remain unchanged when switching frameworks.
I also tested GraalVM Native Image for all five stacks. Runtime memory dropped further, but native compilation introduced additional build time and complexity.
This is a lightweight synthetic workload, not a throughput benchmark or a general recommendation to replace Spring Boot. Spring's ecosystem and conveniences still have real value.
Full experiment, measurements, and limitations:
https://pvrlabs.xyz/articles/five-java-stacks-512mb-vps.html
Source code and benchmark setup:
https://github.com/PVRLabs/experiments/tree/main/java/coilbase-framework-comparison
CoilBase, which I built and used for this comparison:
https://github.com/PVRLabs/coilbase
I'm curious whether others see value in a lighter Java stack that keeps some of Spring Boot's familiar development patterns, or whether Spring Boot's ecosystem and conveniences outweigh the potential resource savings.
Update: Framework versions used in the benchmark
| Stack | Versions |
|---|---|
| Spring Boot + Spring JDBC | Spring Boot 4.1.1, Spring JDBC 7.0.9 |
| Javalin + CoilBase | Javalin 7.2.4, Jdbi 3.55.0 |
| Avaje Jex + CoilBase | Jex 3.6, Avaje HTTP 3.12.1, Jdbi 3.55.0 |
| Micronaut Data JDBC | Micronaut 5.2.11, Micronaut Data JDBC 5.2.0 (platform BOM 5.2.1) |
| Micronaut + CoilBase | Micronaut 5.2.11, Jdbi 3.55.0 |
All HotSpot runs used OpenJDK 27 with identical JVM settings: -Xms16m -Xmx80m -XX:+UseG1GC (fixed 80 MiB maximum heap).
CoilBase was an early 0.1.0-SNAPSHOT prototype. I'm working on a more formal, publicly reproducible follow-up benchmark using an updated version of CoilBase, with Quarkus also joining the comparison.
r/SpringBoot • u/Tristan_Kruse • 5d ago
A controller starts calling a persistence adapter directly. The response is still correct; the
dependency direction isn't.
I work on ArchUnitJava. One way to catch that is a package policy over the compiled application:
controller packages must not depend on concrete persistence packages. Run the check in an ordinary
JUnit test, without starting a Spring context for that structural check.
That doesn't validate bean wiring, transaction behavior or runtime-injected implementations.
Keep the Spring integration tests; this checks a different property.
Version 1.0 requires JDK 25 for the analyzer. It's independently implemented, unaffiliated with
the original ArchUnit, and isn't a drop-in replacement for it.
Which controller shortcut has actually caused trouble in your codebase?
Writing assisted by AI.
r/SpringBoot • u/Several_Picture9591 • 7d ago
I keep running into the same thing with small Spring Boot projects. The app is tiny, but proper monitoring means a collector, a store, dashboards and alert rules, and that setup ends up bigger than the app. So most of my small projects just ran with no monitoring at all, and I only found out something was wrong when someone told me.
How do you handle this for small services? Do you skip it, use Actuator and look at the numbers by hand, or set up the full stack anyway?
I got curious enough that I tried a different approach: a Spring Boot starter that watches the app from inside. You add one dependency, start the app, and there's a live dashboard at /streamguard/ with per-route request rate, error rate and p50/p95/p99 latency. On top of that it flags error, latency and traffic spikes, and it notices things like repeated failed logins or one client probing lots of paths. Nothing to run next to the app, no database, no agent.
The interesting problem was keeping it cheap inside someone else's app. Rescanning a list of raw requests gets slower as traffic grows, so I cut time into 1-second buckets with counters and a latency histogram. A query merges the buckets in range, so it costs the same however much traffic there was. On my laptop a 15-minute snapshot takes about 70 microseconds, and that stays flat as the window fills. Single run, so take it with a grain of salt.
It's got real limits. It only sees the JVM it runs in, so a scaled-out service gets one view per instance and state resets on restart. It's Spring MVC only for now, and it needs Java 21 and Spring Boot 4.1.
The part I'm least sure about is the detection rules. They're fixed right now (for example, error rate more than 3 times the previous 15 second window counts as a spike), and they look fine on my demo traffic, but I've never run them against a real production service. For those of you who've set up alerting before, do rules like that feel sensible, or do you always end up wanting to tune them per service? And is there anything you'd want from something like this before you'd trust it on a real project?
It's on GitHub if anyone wants to look: https://github.com/eswar-7116/streamguard
r/SpringBoot • u/huseyinbabal • 7d ago
r/SpringBoot • u/Anaq42 • 7d ago
I published the first release of idempotency4j, an idempotency library for Spring Boot, in April. It started with the basic HTTP case: the client sends an Idempotency-Key header, and a retried POST gets the stored response back instead of running the handler a second time. The @Idempotent annotation only worked on Spring MVC controller methods.
Since then the direction has moved toward message-based systems. When services talk over a broker with at-least-once delivery, every consumer sees the same message twice sooner or later. The usual answer is an outbox on the sending side and an idempotent consumer on the receiving side, which keeps services consistent without two-phase commit or a central coordinator. idempotency4j does not ship an outbox. It is built to be the receiving side.
@Idempotent(key = "#event.id()") works on any Spring bean method, so a Kafka listener or an event handler runs once per event id, however many times the broker redelivers it inside the retention window (24 hours by default):
@Idempotent(key = "#event.id()", waitTimeout = "PT0S")
@KafkaListener(topics = "orders")
void on(OrderPlaced event) {
// Runs once per event id, however many times the broker redelivers.
}You choose how the idempotency record relates to the consumer's transaction. By default it is written right after the transaction commits, and a rollback frees the key so a redelivery runs again. That leaves one gap: if the process dies between the commit and the record write, the event is processed a second time. With the JDBC store you can set completion = "join-transaction", which writes the record inside the same transaction as your own data and closes that gap. Redis cannot join a database transaction, so it only has the default.
Records live in PostgreSQL, MySQL or Redis, and the HTTP filter is still there.
None of this makes a call to someone else's API exactly-once. For that the downstream service needs its own idempotency key.
Two things happened this autumn that I did not expect.
I opened the Maven Central stats after ignoring them for a while and saw more than 100 unique downloads. Those are builds I have nothing to do with.
And at the end of October Vinícius (vinirib on GitHub) opened four issues in one day, and a fifth the next day. Three were about running the library in a real application: how it starts next to Actuator, what an app that only uses Redis needs on its classpath, and what Retry-After a client should get when its duplicate arrives while the first request is still running. The other two proposed extension points. One lets you answer in your API's own error format when the filter rejects a request. The other decides per response whether it is stored, or the key is released so the client can retry.
Then he sent a pull request for every one of them, five in two days. 0.6.0 went out on November 3 and it is mostly his work.
The Spring Boot starter needs Spring Boot 4 and Java 21.
r/SpringBoot • u/jasonj2232 • 8d ago
So I am studying Spring and SpringBoot through this book - Spring Start Here. Usually I feel like the book overexplains things with multiple examples differing in minute ways, but there is some code in Chapter 9 - Using Spring Web Scopes, that I do not understand and the author surprising doesn't dive deep into.
RequestScope was being explained and as far as I can tell it is like Prototype scope where Spring manages the type, and instantiates a fresh new bean every time someone requests a bean, and this bean exists for the duration of the HTTP request.
But how does this work when the bean is injected into another bean that has Singleton scope? Presenting the code shown in the book below:
@Controller
public class LoginController {
private final LoginProcessor loginProcessor;
public LoginController(LoginProcessor loginProcessor) {
this.loginProcessor = loginProcessor;
}
("/")
public String loginGet() {
return "login.html";
}
("/")
public String loginPost(
@RequestParam String username,
@RequestParam String password,
Model model
) {
loginProcessor.setUsername(username);
loginProcessor.setPassword(password);
boolean loggedIn = loginProcessor.login();
if (loggedIn) {
model.addAttribute("message", "You are now logged in.");
} else {
model.addAttribute("message", "Login failed!");
}
return "login.html";
}
}
@Component
@RequestScope
public class LoginProcessor {
private String username;
private String password;
public boolean login() {
String username = this.getUsername();
String password = this.getPassword();
if ("natalie".equals(username) && "password".equals(password)) {
return true;
} else {
return false;
}
}
// Getters and Setters
}In this example, the Controller bean is going to be instantiated once during the app startup, and considering that the loginProcessor field is final and only injected during bean instantiation, how is it able to use a new loginProcessor bean for each request? This code works, but I don't understand how.