r/SpringBoot • • Dec 30 '25

Question Exception Handling Strategies

14 Upvotes

My strategy for catching exceptions consists of using a global exception handler as a last resort and for automatically thrown exceptions like the ones thrown by Jakarta Valid annotation for user request validation. They're helpful too for 500-range errors to provide a nice message to the user.

For exceptions that can be handled though, it tends to get a bit confusing. An IO expction or a database query resulting in an empty set (not found) can be either handled within the controller or service body, or declared in a throws clause and bubbled all the way up to global handlers.

  1. I might let the exception bubble or get re-thrown from the repository, service, etc. layers as is like a NoSuchElementException, all the way through the controller and to a global exception handler, which should be equipped to add the appropriate status code and message.
  2. or re-wrap it into a more response-friendly custom exception like NotFoundException with a message and status code properties, then let it through and catch it with a global handler which should generate the proper response.
  3. or catch the native exception within the controller after letting it bubble, then return an error response to the user with a ResponseEntity including appropriate status and message without resorting to global handlers at all.

Which method do you use for those exceptions and why?


r/SpringBoot • • Dec 30 '25

Question What's the correct/most used way to use secrets in a SpringBoot project?

9 Upvotes

I will keep it to the point:

> Following is a docker-compose file that I plan to use
> Need to use sensitive information like the DB password inside it
> Putting it directly does not seem like a good idea- unless it is?
> How to do it

services:
  db:
    image: postgres:latest
    ports:
      - "5432:5432"
    restart: always
    environment:
      POSTGRES_PASSWORD: changemeinprod!
  
  adminer:
    image: adminer:latest
    restart: always
    ports:
      - "8888:8080"

r/SpringBoot • • Dec 30 '25

Question Short on Time and Money as a College Student, Need Guidance to Reach and Finish Spring Boot Quickly.

Post image
1 Upvotes

I need to learn Java Spring Boot in less than 4 weeks and somehow land an internship after that. Normally, I do not believe in rushed learning, but due to my current financial situation, I do not really have that luxury. I am still a student and I genuinely do not want to put more pressure on my parents for my expenses, so I am trying to be as practical as possible.

So far, I have already learned HTML, CSS, JavaScript (yeah yeah, average Joe Harry type stuff), Node.js, and I recently finished Express.js. My main goal is to learn backend development using Java Spring Boot.

I need help on the following points:

  1. What are the bare minimum additional tech stacks or concepts I should learn so that I can comfortably start learning Java Spring Boot?
  2. Any YouTube channel, playlist, or Udemy course you would strongly recommend for Spring Boot.
  3. Any other advice you would like to give, since I am still a student and a lot junior to you

Thanks in advance.


r/SpringBoot • • Dec 29 '25

Question How can I make the tests complete faster?

6 Upvotes

I'm creating an API in Spring Boot and I've noticed that the tests I'm creating are taking a very long time to complete, even though I'm not loading much context or even making calls to the endpoints yet. I suppose when I do, each call will take about a minute. What do you recommend?


r/SpringBoot • • Dec 29 '25

Discussion Templates to start a spring project

0 Upvotes

The new status quo for project initialization is that, the build tool itself gives you a command to start a project. Maven, or gradle does not provide a template for that.

But JPM does : $ jpm create simple-spring-app

That simple, if other dependencies are required : $ jpm install org.springframework.boot spring-boot-starter-thymeleaf