r/SpringBoot • • Jul 18 '26

Question React + Spring Boot: If session auth is recommended, how is CSRF handled when frontend and backend are separate?

42 Upvotes

I am trying to understand how CSRF works in a setup where the backend is Spring Boot (API) and the frontend is React, both running as separate applications.

From what I have read, session-based authentication is recommended in many cases. The flow is:

User logs in.

Spring Boot creates a session.

Browser stores the session ID in an HttpOnly cookie.

But since cookies are sent automatically, doesn't that make the app vulnerable to CSRF?

My understanding of CSRF is: When the page is rendered, Backend generates a CSRF token and associates it with the user's session, and includes it in the HTML (hidden form field or meta tag). When the form is submitted, the backend compares the submitted token with the one stored in the session.

This makes sense when the backend renders the frontend (like Thymeleaf). But with a separate React app, how does React get the CSRF token and send it back? How is this usually implemented in Spring Boot?

Also, if storing a JWT in a cookie also makes it vulnerable to CSRF, where is a JWT supposed to be stored? I've seen people say localStorage, sessionStorage, and HttpOnly cookies, but each seems to have its own trade-offs.

I'm looking for the recommended approach for a Spring Boot + React setup.


r/SpringBoot • • Jun 15 '26

How-To/Tutorial Spring AI for beginners: build your first AI app in Java

Thumbnail
protsenko.dev
42 Upvotes

Hi guys,

Been using Spring AI lately and figured I’d share, since I didn’t expect to like it as much as I did.

If you’re already in the Java/Spring world, it’s worth a look. Building a chat client, wiring up RAG over your own docs, exposing an MCP server: all of it was a lot less painful than I assumed it’d be.

The part that actually sold me was local models. I like running models locally to see how they hold up, and connecting them through LM Studio was so easy.

I ended up writing a guide while figuring this stuff out, covering all the topics above. Feel free to share your feedback or experience using it.


r/SpringBoot • • Feb 08 '26

How-To/Tutorial Reading spring start here is the best decision I have made to learn spring

42 Upvotes

I had been struggling with understanding spring and spring boot, I had tried reading the docs, watching yt videos, etc. But I could never internalize why things are done this way and what's even the point of having this framework. I just felt like a code monkey mindlessly typing code that somehow works and used ai to help me build projects. I finally decided that I would like to deep dive into spring and spring boot internals and going through this subreddit I found many people recommending this book. And finally things just click, I finally understand beans, aop, dependency injection, etc. I have always just learnt these topics by reading their theory or watching a yt explanation video and hoping it would click, but the book provides examples that I coded myself and played around with to finally understand what's the point of the framework to begin with. I turned off my copilot autocomplete and only used chatgpt to understand parts of the code that failed and tried understanding why it failed instead of just accepting its solution. For anyone trying to learn spring boot, building projects is good but I would recommend trying to learn spring first, things will make more sense. Of course I am not sure if I am wasting my time learning things the old fashioned way in this new age where we probably won't be writing much code and be outsourcing it to llm agents but I can't predict the future and for now I feel like spring start here is an amazing resource to understand spring and spring boot.


r/SpringBoot • • Apr 10 '25

Guide A collection of Springboot portfolio projects to use as starting point

42 Upvotes

Found this playlist with a bunch of easy-to-follow springboot projects.

I feel like they are a very good starting point to increase the number of projects in our portfolios and maybe use them as starting point. They are more targeted towards people that already know Java.

https://youtube.com/playlist?list=PLJce2FcDFtxK_CpZyigj2uDk7s35tQbpt&si=ynRb6mAvvnhLCeRF


r/SpringBoot • • Mar 22 '25

Question Best Spring Boot microservices course for building a real project?

42 Upvotes

Hey folks,
I’ve got around 2 years of experience with Java and Spring Boot, and I’m looking to properly learn microservices. I want a course that actually helps me build a real-world project I can showcase in job interviews, not just a basic CRUD tutorial.

Ideally something that covers things like Eureka, API Gateway, Config Server, Docker, maybe RabbitMQ, and explains how everything fits together.

If you’ve taken a course that really helped you, I’d love to hear your recommendation. Free or paid is fine. Thanks!


r/SpringBoot • • Mar 18 '25

Guide A fun springboot notifications project to add your portfolio

42 Upvotes

I found this to be a fun little project to add to my portfolio. I think people here will find it useful.

It basically uses Nasa API to send email notifications. It covers also kafka. It’s not too long so perfect to get something to start and expand.

https://youtu.be/6EYZzgWkKaY?si=BNbKw29yKqs8FmEl


r/SpringBoot • • Jan 15 '25

Question Resource recommendation for Spring Security

42 Upvotes

So far I haven't had any problems with Spring Boot, but Spring Security has made my head spin.

I'm not a video guy. I understand better with more written and practical things. But of course I can also look at the video resources that you say are really good. If you have resource suggestions, I would be very happy

Edit: You guys are amazing! I discovered great resources. Thanks for the suggestions!


r/SpringBoot • • Aug 05 '26

How-To/Tutorial How we structure Entity/DTO mapping in a multi-module Spring Boot project (without MapStruct)

41 Upvotes

Something has always bugged me about relying on annotation-based mapping frameworks once a Spring Boot project grows past a few modules. MapStruct is miles ahead of dynamic tools like ModelMapper thanks to compile-time code generation, but we kept running into recurring friction as our domain, entity, and DTO layers diverged.

That's why we ended up dropping MapStruct entirely in favor of plain Java transformer classes. No annotation processor, no generated sources, no separate mapper interface per entity pair.

The reasons that pushed us there:

  1. Fragile IDE refactoring: string path mappings like `@Mapping(source = "shippingDetails.address.street", target = "street")` don't reliably survive a rename. You usually catch it during the build, sometimes later.

  2. Annotation pollution for anything non-trivial: once you need a custom transformation, you're writing @Namedhelpers or embedding Java inside annotation strings likeexpression = "java(...)".

  3. Debugging noise: stepping through target/generated-sources instead of your own domain code.

The trade-off is real - more files, more explicit code to write. What we get back is full IDE refactoring safety, no annotation-processor step in the build, and a debugger that only ever shows real code.

Anyone else moved off MapStruct in a modular Spring Boot setup, or is this more trouble than it's worth for most projects?

(I Wrote a deeper architectural breakdown with code samples if anyone is interested - link in comments).


r/SpringBoot • • Aug 01 '26

How-To/Tutorial How should I start Spring Boot?

41 Upvotes

I have Knowledge of Jdk17+ currently moving to Jdk21+. I have essentially completed Java.utils.*; and concurrent library to deep. I have also used jdk tools and understand the concepts of JVM, JMM. OOPs is completed from beginner to F-Form polymorphism. I also made project based on Java SE knowledge. The project is tested on JUnit6, JCStress, JMH- with Linux profilers and Java Flight recorder too. It's my first time I am going Outside domain of Java SE to Java EE. What is way should I start?
First JDBC->SQL->PostgressSQL?
Network?
SpringBoot?
or learn while learning SpringBoot?
Can you tell me what beginners mistake I should avoide?
I have also took helped from many other AI but I did not got the optimum way.


r/SpringBoot • • Jul 14 '26

Discussion I built a Spring Boot testing library to detect N+1 query problems

41 Upvotes

Hi everyone,

I’ve been working on an open-source testing library for detecting N+1 query problems in Spring Boot applications using Hibernate:

https://github.com/fabioformosa/n-plus-one-query-problem-detector

The idea is to catch N+1 regressions during integration tests, instead of discovering them later through slow endpoints or production monitoring.

The library currently supports two main approaches.

Scan mode can analyze an existing Spring integration test suite without requiring changes to individual tests. It monitors Hibernate statistics and repeated SQL patterns, then produces a report of possible N+1 candidates with different confidence levels.

You only need to enable it in your test configuration:

n-plus-one-query-detector.scan.enabled=true
n-plus-one-query-detector.scan.report.output=stdout

There is also an explicit assertion mode for tests where you want to enforce a query budget:

@SpringBootTest
@ExtendWith(NPlusOneQueryProblemDetectorExtension.class)
class CompanyServiceTest {

    
    private CompanyService companyService;

    
    @ExpectMaxQueries(1)
    void listCompaniesWithoutNPlusOneQueries() {
        companyService.list(0, 5);
    }
}

The project supports Spring Boot 3.5.x and Spring Boot 4.x.

I’d be especially interested in feedback about:

  • the scan-mode detection approach;

  • possible false positives you encounter in real applications;

  • the assertion API and developer experience;

  • features that would make this useful in your CI pipeline.

The project is still evolving, so issues, suggestions and contributions are very welcome.


r/SpringBoot • • Jul 12 '26

Discussion Used ShedLock in production for few months now. Sharing my experience.

41 Upvotes

We have scheduled jobs in our Spring Boot services.

We was using spring bootScheduled annotationfor syncing data and sending notifications.

It worked fine when we had one instance but then we decided to scale to multiple pods and regions in openshift cloud platform, so using Scheduled will run the job on each pods.

We decided to go with Shedlock as it is small library and the idea is simple, before a job runs, it takes a lock in a shared store. If another pod already took the lock, the job just skips. For shared store, we used Couchbase as ShedLock has a Couchbase lock provider.

Few months in production now with zero duplicate runs, just take care of below two things.

First is that lockAtMostFor is important. If your pod dies mid job, this is how long the lock stays before another pod can pick it up. You can set it a bit longer than your worst case job time. And second is that ShedLock will not retry or re run missed jobs. It only makes sure at most one instance runs.

What other solution you have used for same problem?


r/SpringBoot • • Feb 25 '26

How-To/Tutorial Built my first AI app entirely in Java using Spring AI

41 Upvotes

Built my first AI app entirely in Java using Spring AI — no Python involved

I've been experimenting with Spring AI (the official Spring project for AI integration) and was surprised how little code it takes to get something working.

The whole setup is one Maven dependency and a few lines of YAML config. From there I built three things on top of the same project:

  • A simple chat endpoint using ChatClient — literally prompt(), call(), content()

  • Structured output that maps AI responses directly to Java records (no JSON parsing)

  • Tool calling where the AI invokes Java methods to get real data

The tool calling part was the most interesting — you annotate a method with @Tool and Spring AI handles the function-calling protocol with the model. The AI decides when to call your code and uses the result in its response.

I recorded the whole process if anyone wants to see the code in action: https://youtu.be/SiPq1i_0YgY

Anyone else using Spring AI in production or side projects? Curious what use cases people are finding beyond chat endpoints.


r/SpringBoot • • Jan 10 '26

Question Spring Boot + JPA: Best practices for entity relationships, fetching, and performance?

41 Upvotes

I’m using Spring Boot with JPA/Hibernate and wanted to ask about real-world best practices.

Mainly around:

  • Entity relationships

  • LAZY vs EAGER fetching

  • Avoiding N+1 queries

  • DTOs vs entities

  • Repository vs service responsibilities


r/SpringBoot • • Dec 18 '25

News Next level Kotlin support in Spring Boot 4

Thumbnail
spring.io
41 Upvotes

r/SpringBoot • • Aug 28 '25

Question What should I learn next after Spring Boot (sync), Spring Data, Spring Security, Docker, GitHub Actions, and Nginx?

41 Upvotes

I feel like I have a good grasp of building synchronous applications with Spring Boot. I’m comfortable with Spring Data for persistence, Spring Security for authentication/authorization, and I usually deploy my projects with Docker + GitHub Actions + Nginx.

Now I’m trying to figure out what the next step should be to level up.

For those who’ve been through this path, what did you focus on next after reaching this stage?


r/SpringBoot • • May 27 '25

Question What are some real-world, large-scale backend projects (like Hotstar, Dream11, Uber) I can build using Spring boot microservices that solve real business problems and showcase advanced engineering?

41 Upvotes

I'm a backend engineer diving deep into system design and advanced backend engineering. I'm looking to build production-grade, large-scale Spring boot microservices projects that solve real-world business problems and demonstrate the skills required to work on systems handling millions of users, high concurrency, distributed transactions, etc.

I'm heavily inspired by creators like Hussein Nasser, Arpit Bhayani, and Gaurav Sen, and I want to build projects that show expertise in:

Distributed systems

Event-driven architecture (Kafka, Redis pub/sub)

Caching (Redis, CDN)

Horizontal scalability

Database sharding, replication, eventual consistency

Observability (Prometheus, Grafana)

Kubernetes, containerization, CI/CD

Real-time data streaming (WebSockets, SSE)

Rate-limiting, retries, fault tolerance

I’ve already shortlisted a massively scalable sports streaming platform (like Hotstar or JioCinema), but I’d love to explore more high-impact ideas that could potentially solve real problems and even evolve into startups.

So far, here's what I've brainstormed:

  1. Live Sports Streaming Platform with Realtime Commentary + Polls + Leaderboards

  2. Real-time Stock Trading Simulator (with order matching, leaderboard)

  3. Uber-style Ride Matching Backend with Geospatial Tracking + Surge Pricing

  4. Distributed Video Compression & Streaming Service

  5. Online Ticketing System (with concurrency-safe seat booking)

  6. Real-time Notification Service (Email/SMS/Webhooks with Kafka retries)

  7. Decentralized Learning Platform (like Coursera backend)

  8. Personal Cloud Storage System (Dropbox-like)

  9. Multiplayer Gaming Backend (matchmaking, state sync, pub/sub)

I want to simulate millions of users, stress test my system, and actually showcase this to recruiters and architects.


Questions:

  1. What other high-impact, real-world problems can I solve with a complex backend system?

  2. Which of the above do you think has the most real-world application and is worth pursuing?

  3. Any tips on how to simulate high load / concurrency / scale on a personal budget for such systems?

  4. Bonus: If any of these can evolve into startup ideas or SaaS products, I’m open to brainstorming!


Thanks in advance! I’m treating this like my “startup-grade portfolio” and would love feedback from experienced folks!


r/SpringBoot • • Feb 21 '25

Question What Are the Must-Have Skills for a Solid Spring Boot Toolbox?

41 Upvotes

I’m already comfortable with the basics but I want to know what key topics and features are essential for developing spring boot applications.

What do you consider indispensable for a Spring Boot developer? Are there any hidden gems or resources you swear by?


r/SpringBoot • • Nov 30 '24

Any interesting open source enterprise-grade projects using Spring Boot?

41 Upvotes

Hi everyone,

I’m exploring Spring Boot and am curious if there are any interesting open source projects out there that are enterprise-grade or demonstrate advanced use of Spring Boot in real-world scenarios.

I’m looking for projects that go beyond the basics—perhaps with robust implementations, integrations with other enterprise tools, microservices, or examples of scaling Spring Boot in production.

Would love to hear your recommendations or any cool projects you’ve come across.


r/SpringBoot • • Nov 13 '24

Java, Spring and gRPC

41 Upvotes

Let me introduce the grpc-starter project—Spring Boot starters built for the gRPC ecosystem and modern Java.

Project Background:

About two years ago, my company decided to fully embrace gRPC and modern Java (17). We wanted to build a solid foundation for our Java services using Spring and gRPC. So, I looked into existing Spring and gRPC integrations and found two relatively mature implementations: grpc-spring and grpc-spring-boot-starter. But they all had similar issues:

  1. Lacked Support for the gRPC Ecosystem: They didn’t support essential tools around gRPC. For us, protobuf message validation (protoc-gen-validate/protovalidate) was a must-have. Later, we also needed grpc-gateway to support both gRPC and HTTP/JSON with a single codebase.

  2. Not Very Active and Not Friendly with Newer Java and Spring Versions: This isn’t good news considering how fast Java is evolving; there’s a risk these frameworks could become outdated.

  3. Integration Wasn’t “Native” to Spring: They introduced unnecessary concepts and annotations, and even did some hacky stuff (like the way they injected gRPC client beans).

  4. No GraalVM Support: I’m not a huge fan of GraalVM, but it’s definitely a nice feature to have.

So, I started the grpc-starter project. The main goals are:

  • Embrace Modern Java and Spring Boot: The version is always in sync with Spring Boot.

  • Designed for Extension: Easily extend it based on your needs and effortlessly integrate other frameworks or libraries.

  • Built-in Protobuf Message Validation: both protoc-gen-validate and protovalidate.

  • Provide a Java Implementation of gRPC-Gateway (maybe the only one)

  • Integration Over Abstraction: The project doesn’t introduce concepts beyond Spring and gRPC. If you’re familiar with Spring or gRPC, you do a quick start.

  • Full GraalVM Support

This project has been battle-tested and currently powers all Java services in my company. It’s working great, and the feedback has been awesome. I’d love for you to give it a try and let me know what you think!

BTW, I have known that Spring started spring-grpc. I checked out its code, and it mainly focuses on client/server auto-configuration. I think it’s got a long way to go before it’s production-ready. :)


r/SpringBoot • • Sep 13 '24

Open sourced spring boot projects

41 Upvotes

Hye I'm a spring boot developer with barely 1 year of experience. I would like to know if you guys know any open sourced backend projects/codebases so I can learn on how to develop the backend more professionally, read on how others solve some basic business logics and so on.


r/SpringBoot • • Nov 06 '21

Kafka Spring Boot Order & Shipping example

Post image
41 Upvotes

r/SpringBoot • • Sep 07 '26

Question Entity Graph seems to defeat the purpose of Lazy Loading?

40 Upvotes

So I've been dealing with an N+1 problem in my Spring Boot app. FYI I didn't set up the lazy loading myself, it was already like that in the codebase I inherited. But basically I'm hitting the DB, then because of lazy loading, some attributes aren't there yet, so I end up going back to the DB again in a separate query just to grab them. Classic N+1.

I looked into it and found that Entity Graphs are supposed to fix this by fetching everything (or specific attributes) in one go instead of triggering extra queries.

But now I'm confused... isn't that basically the same as just using EAGER fetch? Like what's even the point of setting up LAZY loading in the first place if I'm just going to turn around and use an Entity Graph to eagerly fetch the exact attributes I need anyway?

Is the difference just that Entity Graph lets you choose which relations to fetch eagerly on a per-query basis, instead of committing to EAGER globally on the entity itself? So it's more like "controlled/selective eager fetching" rather than actually lazy?


r/SpringBoot • • Apr 09 '26

Discussion Struggling to understand Kafka (Java Developer – 2 yrs exp) – Need good resources 🙏

40 Upvotes

Hi everyone,

I’m a Java Developer with around 2 years of experience, mainly working with Java, Spring Boot, and REST APIs.

Recently, I started learning Apache Kafka, but I’m finding it quite difficult to understand concepts like producers, consumers, partitions, offsets, and real-time processing. I’m not able to connect the theory with practical use cases properly.

Could you please suggest some good resources (videos, courses, blogs, or docs) that are beginner-friendly but also helpful for interview preparation?

My goal is to at least get Kafka concepts clear enough to confidently answer interview questions.

Also, if you have any tips or a roadmap on how to approach Kafka as a Java developer, that would be really helpful.

Thanks in advance! 🙌


r/SpringBoot • • Apr 01 '26

Question What makes a backend project look “industry-level” (for a fresher)?

40 Upvotes

Hey devs,

I’m a fresher working on a backend assignment:
Finance Data Processing + Role-Based Access Control (RBAC)

It includes:

  • Users + roles (viewer/analyst/admin)

  • Financial records (CRUD + filters)

  • Dashboard summaries (totals, trends)

  • Access control + validation

My goal isn’t just to make it work — I want it to look clean and industry-level.

Quick questions:

  • What actually makes a backend project stand out to you?

  • Biggest mistakes freshers make?

  • Better to keep it simple & clean OR add advanced stuff (Redis, rate limiting, etc.)?

Stack I’m thinking: Spring Boot + PostgreSQL + JWT + Swagger + deployment

Would really appreciate honest feedback