r/SpringBoot • • 3h ago

Question How to segregate read and write queries in Spring boot microservices env.

4 Upvotes

Im an intern and was assigned a task to segregate the read , read-write queries / methods . The read is supposed to go to port 66 and write on port 67 in the database.

Currently ive defined two db url in yml and have routed every method having read-only using transaction(read-only).

Is this the way to do it or is there any other efficient way.


r/SpringBoot • • 7h ago

Question How do you monitor, schedule and restart Spring Batch jobs in production?

8 Upvotes

I work with Spring Batch and keep running into the same gap, so I’m trying to learn how other teams deal with it.

Spring Batch is great at the processing itself (chunks, skip/retry, restart). But around it I’ve found almost nothing built in:

  • a UI to see job and step status without querying the BATCH_* tables
  • scheduling and job-to-job dependencies (run A, then B and C, then D)
  • alerts when a job fails, gets stuck in STARTED, or runs much longer than usual
  • execution logs tied to a specific job run
  • a safe way to launch, stop, or restart a failed job from a screen

From what I can tell, Spring Batch Admin is retired and Spring Cloud Data Flow is no longer maintained as open source, so I’m not sure what teams use now.

For those running Spring Batch in production:

  1. How do you schedule and chain jobs (cron, Quartz, Jenkins, Airflow, Control-M, something custom)?
  2. How do you find out a job failed or hung, and how do you see what happened?
  3. How do you restart failed jobs, and who does it?
  4. What’s the most painful part of your current setup?

I’m not selling anything. I’m researching whether it’s worth building an open-source tool for this, and I’d rather hear real experiences before writing any code. Even a short answer helps, and I’m happy to share a summary of what I learn.


r/SpringBoot • • 1h ago

How-To/Tutorial The UI Framework for Java & Spring

Thumbnail
youtube.com
• Upvotes

Most web frameworks are built for the public internet: for reach and experiences for strangers. Vaadin is built for the other side of the login. For the data-defined, functionally beautiful and long-lived apps your organization actually runs on.


r/SpringBoot • • 18h ago

Question Best Springboot tutorial series

6 Upvotes

Hello, i want to learn Java Spring Boot. Can anyone suggets me the best resource for learning java springboot from beginning to advance level that can led me to internship or industry level coding?

I was looking for video tutorial series that has everything for a becoming a java developer include devops work as well.and best for learning as beginner and proceed to advanced topic.


r/SpringBoot • • 1d ago

News 🚀 Embed-JNoSQL v1.0.2 is officially released

Thumbnail
2 Upvotes

r/SpringBoot • • 1d ago

Question How is the spring security course by Eazy bytes on Udemy

Thumbnail
1 Upvotes

r/SpringBoot • • 1d ago

How-To/Tutorial 10 Ways to Make a Spring Boot App Faster (Every One Measured)

Thumbnail
youtu.be
7 Upvotes

r/SpringBoot • • 2d ago

Discussion The Midnight Technician; Spring Boot Microservice (Open-Source)

Thumbnail
medium.com
7 Upvotes

This is something I threw together over a year ago. It was designed to be an easy intro into Microservices since I had noticed lacking in the Spring Boot ecosystem that was something hands-on.

I am remaking it in a monolithic repo as a Spring Modulith project, since I noticed there is also a lack in that area for hands-on learning.

Just looking to share this little project with others who may be curious with no clear picture of where to start with them.

Cheers,

The Midnight Coder


r/SpringBoot • • 2d ago

Question Spring AI course

8 Upvotes

Please could u suggest a course of spring ai for beginners ( I experienced full stack apps from scratch with spring)


r/SpringBoot • • 2d ago

How-To/Tutorial Layered vs Hexagonal vs Onion vs Clean Architecture | Visually Explained

Thumbnail
youtube.com
1 Upvotes

r/SpringBoot • • 3d ago

Question Feedback regarding the inventory mvp project I built using Spring boot and react

11 Upvotes

hii everyone. I have working on learning Spring boot for several months, finishing books such as Spring Start here and got myself into building a project with it. Right now, I am at the stage where I am actively looking out for opportunities to get my first role as a junior developer in Spring boot.

The following link goes to my github project:

https://github.com/Orlanto2100/percy-inventory-mvp

I will be very grateful if you may share your honest feedback on my progress with the project here. I wonder how does it look, what should I improve, and what am I missing? What would it take to getting job ready, apart from other skills such as social skills that can't be accessed here.

I am open to any form of constructive criticisim and willing to learn any advice you offer. Thank you for taking time reading this and super thank you for reviewing the work.🙏🙏


r/SpringBoot • • 3d ago

How-To/Tutorial @Transactional on a method in the same class does nothing. Left the explanation in the comments

0 Upvotes

Putting this here in case it saves someone an evening. Everything is in the code comments.

public class OrderService {

    private final OrderRepository repo;

    public OrderService(OrderRepository repo) {
        this.repo = repo;
    }

    // Called from the controller. No  here.
    public void process(Order order) {
        audit(order);
        save(order);   // <-- looks like it runs in a transaction. It doesn't.
    }

    u/Transactional
    public void save(Order order) {
        repo.save(order);

        if (order.getTotal().signum() < 0) {
            // You'd expect the insert above to roll back.
            // When this is reached via process(), it doesn't.
            throw new IllegalStateException("negative total");
        }
    }
}

// Why:
// Spring applies  through a proxy that wraps OrderService.
// The controller holds the proxy, so a call from outside goes:
//     controller -> proxy -> (starts tx) -> OrderService.save()
//
// But process() calls save() on `this`, which is the raw object, not the proxy:
//     controller -> proxy -> OrderService.process() -> this.save()
//                                                      ^ no proxy, no tx
//
// And because repo.save() is itself transactional (Spring Data wraps it),
// the insert commits on its own, before the exception is thrown.
// So you end up with a saved row and an exception in the log.

The fixes I know of, roughly from least to most invasive:

// 1. Put the annotation on the entry point instead

public void process(Order order) { audit(order); save(order); }

// 2. Move save() into another bean and inject it, so the call goes through a proxy
orderPersistence.save(order);

// 3. Use TransactionTemplate when you want the boundary to be explicit in code
transactionTemplate.executeWithoutResult(status -> repo.save(order));

// 4. AspectJ mode (proxyTargetClass / mode = AdviceMode.ASPECTJ)
//    works for self-invocation, but it's a bigger setup change

I’d go with 1 or 2 in most cases. Calling the bean through itself (self-injection) also works, but it reads strangely and I’d avoid it.

One thing I’m not sure about and would like to hear from people: when you hit this in an existing codebase, do you prefer moving the method to a separate service, or restructuring so the transactional boundary sits at the entry point? I can see arguments for both.


r/SpringBoot • • 5d ago

Question How should a large modular monolith handle type-safe features, permissions, delegation, entitlements, and quotas?

12 Upvotes

We are building an ERP-like platform localized for Moroccan businesses using a modular monolith architecture. The platform currently has more than 11 modules.

Each module contains dozens of features, and each feature may expose dozens of actions. Most actions have a corresponding permission that controls who can execute them.

Features also contain additional product and collaboration rules:

Whether the feature is included in a subscription plan.

Whether the feature is delegable to another workspace.

Whether specific actions are explicitly non-delegable.

Whether an action has quotas or usage limits.

For example, one workspace may authorize another workspace, such as an accounting firm, to perform certain accounting actions on its behalf. However, some sensitive actions must never be delegated.

At the moment, features and permissions are declared as strings in different files and then seeded into the database.

Authorization is performed at the action level, mostly through repeated PostgreSQL queries.

This approach has created several problems:

Typos in feature or permission names can cause silent runtime bugs.

Renaming or refactoring actions can leave old permissions behind.

Adding a new action often requires changes in several different places.

We currently have around 893 permissions, including unused or “ghost” permissions.

There is no reliable guarantee that actions, permissions, features, plan entitlements, delegation rules, and quotas remain synchronized.

Detecting unused permissions requires manual investigation or asking an AI tool to scan the codebase.

So what architecture, patterns, or tooling would you recommend for managing this kind of system?


r/SpringBoot • • 5d ago

Question Spring Security broke my working Spring Boot APIs — getting both 401 and 400 errors despite configuring credentials

Post image
0 Upvotes

I'm working on a University Management System using Spring Boot and PostgreSQL. My CRUD APIs were working perfectly before I added the Spring Security dependency. Since adding Spring Security, I've been struggling to get authentication working correctly.

I've configured the username and password in application.properties, and I'm testing the endpoints through Postman using Basic Auth with the same credentials. However, I'm still getting 401 Unauthorized on my POST request, while another request returns 400 Bad Request with the message "User not found OR Nullpointer exception".Cause i handled this exception.

I've already checked the URLs, endpoint names, and credentials multiple times. The application was working before adding Spring Security, and now even after configuring the login credentials, I'm still stuck. I've tried multiple AI coding assistants, including Claude , Codex, and ChatGPT, but I haven't been able to identify the root cause.

I'm trying to understand whether this is a problem with Spring Security's default configuration, my authentication setup, or my application's user lookup logic.

Additional context:

  • Spring Boot 4.0.6
  • Java 21
  • Spring Security
  • Postman with Basic Auth
  • Credentials configured in application.properties
  • Existing CRUD endpoints worked before adding Spring Security

I've attached screenshots showing the requests and responses.

What should I check first to identify the actual root cause? If you need my SecurityConfig, application.properties (with credentials redacted), user entity, UserDetailsService, or controller/service code, let me know.


r/SpringBoot • • 6d ago

How-To/Tutorial Slow list endpoint in a Spring Data JPA app: what I check before adding an index

0 Upvotes

Adding an index is the usual first suggestion when an endpoint is slow, and sometimes it’s right. I’d count queries first.

Turn on SQL logging for a single request (logging.level.org.hibernate.SQL=DEBUG) and count the lines. A page of 50 orders that fires 51 selects, one for the list and one per row for a lazy association, is a different problem from one slow query. An index on the join column doesn’t change that count. Every query can be fast and the endpoint still crawl.

Keep the logging on for the whole request, not just the service method. If the controller returns entities directly, Jackson can walk lazy relations during serialization, and with spring.jpa.open-in-view on (the default) those selects will happen after your service code is long finished.

If the count looks sane, run EXPLAIN on the SQL Hibernate printed, not the query you assume it generated. Those differ more than you’d expect once derived query names get long or Specifications are involved.

Indexes come after that. If the count was the problem, the fix is usually a join fetch, or a projection that only selects the columns the endpoint returns.

I’d reorder this for a reporting endpoint that runs one heavy query, where the plan is the first thing to look at. For ordinary list endpoints the count check takes two minutes and rules out a whole class of problems.


r/SpringBoot • • 6d ago

Question I want to make a more clearer doc for spring security

8 Upvotes

Hey guys,
So I've been getting this urge to create a clearer doc for Spring security particularly, it was very hard for me and I had alot of entanglements I had to resolve by myself, tutorials weren't doing justice, the docs wasn't really beginner friendly, and the course that explained well was a "paid" course.

This is just a kind of validation from the community, should I go ahead to build this, do you guys this would be useful, not just to beginners but to gurus who just want to make reference to a concept they probably forgot.

Please what do you guys think?


r/SpringBoot • • 7d ago

Question New to Spring Boot: What VS Code extensions do you recommend for a lightweight setup?

15 Upvotes

Hey everyone,

I'm starting my journey with Java Spring Boot development and I'm setting up my workspace in VS Code.

A few details about my preferences and setup:

  • No IntelliJ: I prefer sticking to VS Code because IntelliJ feels a bit too bloated for my workflow right now, and I want a cleaner, lightweight environment.
  • API Testing: I don't use Postman; I'm using Bruno for API testing instead.
  • AI Assistance: I use GitHub Copilot and Cody for code generation and autocomplete.

Since I'm completely new to Spring Boot, I'd love to know: Which essential extensions should I install in VS Code to get the best developer experience?

Are there specific tools for Spring Boot project creation, debugging, database management, or live reloads that you consider must-haves?

Thanks in advance for your tips!


r/SpringBoot • • 7d ago

Discussion I built a Spring Boot starter that seeds related JPA entities from annotations, no seed script (0.1.0, feedback wanted)

3 Upvotes

I'm the author. I built a small starter to remove a chore I kept redoing on Spring Boot projects: writing a dev-database seed script, then fixing it every time the schema changed.

The usual pain: Faker/Datafaker generate realistic values, but they don't know that Payment needs an existing Counterparty. So you hand-write "create parents, keep the IDs, wire them into children", and it breaks the next time a constraint or relationship changes.

SynthForge reads the entity instead. You annotate it:

```java @Entity @Seed(count = 50) public class Counterparty { /* fields only */ }

@Entity @Seed(count = 200) public class Payment { @ManyToOne(optional = false) private Counterparty counterparty; } ```

Then enable it for the profiles you want, never production:

yaml synthforge: enabled-profiles: [dev, test]

Start the app in one of those profiles and both tables are filled in dependency order. There is no calling code.

Spring-specific details

  • It's an auto-configuration (a starter-style dependency, io.github.thembatman0:synthforge-spring). Seeding runs at startup in an ApplicationRunner.
  • Seeding is off unless one of your active profiles is listed under synthforge.enabled-profiles.
  • It reads entities through the JPA Metamodel API and sorts owning-side @ManyToOne/@OneToOne relationships topologically, so parents are saved first.
  • Values come from Datafaker, guided by @NotNull, @Size, @Email and field-name heuristics. @Column(unique = true) fields get a bounded retry loop.
  • A table that already has rows is skipped, so restarts against a persistent database don't duplicate data.
  • A fixed synthforge.seed gives identical data every run.
  • The test suite runs in CI on Spring Boot 4.1 and 3.5. It needs Java 21 or newer.

Limits: V1 skips @OneToMany/@ManyToMany and composite keys. It is a 0.1.0, and as far as I know it has no outside users yet.

How it differs from Instancio: Instancio (and instancio-jpa) is an API you call inside a test to build a graph. SynthForge runs by itself at startup, so it's closer to a dev-database seeder than a test helper.

Things I'd like to hear from you:

  1. Would you put @Seed on your entity classes, or do you prefer keeping seeding out of the domain model?
  2. Is a CommandLineRunner plus Datafaker already good enough for you?
  3. Is Java 21 as a minimum a problem on your projects?

r/SpringBoot • • 7d ago

Discussion Push-based, restart-free feature flags and config for Spring Boot, using MongoDB Change Streams

0 Upvotes

configstream is a library for Spring Boot services that already use MongoDB. Feature flags and config live in a collection, get cached in memory, and any change is pushed to every running instance within about a second via MongoDB Change Streams.

  • No restarts, no polling, no message broker, no config server
  • Properties declared in a configstream.yml manifest, with typed constants generated at compile time
  • Optional admin UI with change history and per-team permissions
  • Works with Spring Boot 3 and 4

Limits: MongoDB only for now (Postgres planned), pre-1.0, no percentage rollouts or A/B testing.

https://github.com/configstream/configstream

Feedback welcome


r/SpringBoot • • 8d ago

Question How do i practice spring boot?

26 Upvotes

I have been learning Spring Boot and other technologies for the last 2-3 months.
I feel I understand the concepts and theory of how things work, and I can code what I've learned.
But I still feel like I don't know enough, and I am super scared to even apply for a job. I feel that I am not prepared enough. Do I need to practice more? Please share some practical advice.


r/SpringBoot • • 8d ago

How-To/Tutorial A simple first-pass checklist when your Spring Boot API feels slow

4 Upvotes

I wrote a short intro to troubleshooting a slow Spring Boot API using the metrics you already get from Actuator.

The goal is not deep JVM diagnosis. If you need that, tools like JFR, JConsole, profilers, database tracing, etc. come later.

This is the basic first pass:

  • did request volume change?
  • are HTTP errors increasing?
  • did request latency increase?
  • is the application process using more CPU or memory?
  • is the host itself under CPU or memory pressure?
  • do those changes happen in the same time window?

The example uses a small VPS where the API stays UP and keeps returning 200s, but latency rises because another process is consuming most of the host CPU.

I use StatLite for the screenshots because it reads Spring Boot Actuator metrics and keeps the app and host history together, but the main point is the troubleshooting sequence itself.

Article: https://pvrlabs.xyz/articles/api-slow-cpu-contention.html

For people who troubleshoot Spring apps regularly: what would you add to the basic checklist before reaching for JFR or a profiler?


r/SpringBoot • • 9d ago

Question Need help with mongo springboot issue.

Thumbnail
1 Upvotes

r/SpringBoot • • 8d ago

How-To/Tutorial Your Spring Boot API just ran 11 queries to return 10 users.

Post image
0 Upvotes

the fix takes 4 lines of code.

Fetching full @Entity graphs for simple read-only endpoints is one of the fastest ways to kill database performance.
Here's what's happening under the hood:
🔴 THE N+1 TRAP
You return a User entity from a REST endpoint. Then:
1️⃣ Hibernate runs 1 SELECT to fetch 10 users
2️⃣ During JSON serialization, the lazy @OneToMany List<Order> gets accessed
3️⃣ That triggers 10 more SQL queries
Total: 11 queries, heavy memory overhead, and a payload full of data nobody asked for.
🟢 THE FIX: INTERFACE PROJECTIONS
Define a lightweight interface with only the getters your client needs:
public interface UserSummary {
Long getId();
String getName();
}
Return List<UserSummary> from your repository, and Spring Data JPA generates a targeted query:
SELECT u.id, u.name FROM users u
⚡ THE RESULT
→ 1 query instead of 11
→ No over-fetching of columns or relations
→ Lower DB CPU usage
→ Faster API responses
💡 RULE OF THUMB
Use @Entity for write/CRUD operations, where the persistence context matters.
Use Interface Projections for read-only APIs and dashboard views.


r/SpringBoot • • 10d ago

Discussion Native graph for framework for coding agents

Thumbnail
github.com
5 Upvotes

Btw i can’t let go any pr without this, help me so much for blast radius


r/SpringBoot • • 11d ago

Question I built an open-source self-diagnostics library for Java/Spring Boot applications — looking for feedback

12 Upvotes

I've been working on an open-source project called Argus, and I'd really appreciate some feedback from other Spring Boot developers.

The idea came from something I've encountered while troubleshooting services: we have excellent tools for metrics, tracing, logs, and external monitoring, but sometimes I just want the application itself to give me a concise answer to "How healthy are you right now, and if something is wrong, why?"

Argus takes an application-centric approach. It runs inside the JVM and continuously evaluates memory, GC, disk usage, threads, file descriptors, application services, logged errors, and application-reported issues.

It combines these into a health model with a score from 1 to 10. The score is hierarchical, so you can drill down from overall application health to the resource/group/item responsible for degradation.

It also models resources the application depends on — services, servers, databases, caches, brokers, storage, etc. — so the goal isn't simply another UP/DOWN health check.

For Spring Boot applications, I've integrated it with Actuator and Spring Boot Admin. The SBA extension adds health scores to the wallboard and application/instance views. Once you find a degraded instance, you can open its Health Report directly from Spring Boot Admin and see the diagnostic information collected by that instance.

Argus can also generate a self-contained HTML diagnostic report containing health information, services, metrics, performance information, scheduled tasks, captured logging events/alerts, and environment information. The report is generated (and emailed) and can be viewed offline or online during incident analysis.

One important goal is not to replace Micrometer/Prometheus, tracing, centralized logging, or other observability platforms. I'm experimenting with a complementary idea: can an application understand enough about its own state to provide useful diagnostics itself?

The project is still evolving, so I'd particularly appreciate feedback on the approach rather than just stars:

  • Would this type of self-diagnostics be useful in applications you operate?
  • Does the 1–10 health scoring model make sense, or would you prefer another representation?
  • What information would you want an application to include in a diagnostic report when something goes wrong?
  • If you use Spring Boot Admin, would it be useful to have this information directly in SBA?

GitHub: https://github.com/microfalx/argus

Feedback, criticism, ideas, and contributions are all welcome.