Get Started with Custom Error Handling in Spring Boot (Java)

Learn how to implement custom error handling logic in Spring Boot. You will see two approaches based on the @ControllerAdvice annotation. Similarly, you will learn how to deal with authentication and access denied errors in Spring Security.
Read more…

Brought to you by one of our Guest Author crew Antonello Zanini

What are you thoughts Folks? Share it in the comments! 🧑‍💻

Please use this below on the ErrorResponse instead of putting those on the class level, no getter and setter are generated by lombok for PRIVATE fields.

   @Getter @Setter private Date timestamp;

@Getter @Setter private int code;

@Getter @Setter private String status;

@Getter @Setter private String message;

@Getter @Setter private String stackTrace;

@Getter @Setter private Object data;
1 Like

Hi! I’m the author of the article.

That’s weird, actually. It shouldn’t be happening. As stated here in the official documentation:

You can also put a @Getter and/or @Setter annotation on a class. In that case, it’s as if you annotate all the non-static fields in that class with the annotation.

In this article, they’re adopting the approach I took in the article as well. In other words, @Getter @Setter at class level should work with private fields.

Anyway, thanks for sharing your solution to the problem you encountered!

1 Like

Thank you for this blog. It worked well! Keep Spreading the Knowledge :slight_smile: <3