Questions tagged [controller-advice]

113 questions
3
votes
1 answer

Java Test for Spring ExceptionalHandler

I have a springboot project with controllers and servies. And a GlobalExceptionHandler like - public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler(DataIntegrityViolationException.class) public…
Akanksha
  • 181
  • 3
  • 8
3
votes
0 answers

How to Integrate Test @RestControllerAdvice which Has Dependencies?

I have a simple @RestController in Spring Boot 2.1 which has a @RestControllerAdvice assigned to it to handle exceptions, e.g. @RestController @RequestMapping("/path") public class MyController { @Value("${some.property}") private boolean…
2
votes
1 answer

Global Exception Handler / @Controller Advice on spring boot 3.0 not being applied

I have recently migrated my application from spring boot 2.1 to spring boot 3.0. But the problem is that now there are endpoints which are not giving the same response when an error happens, instead I get something like this: { "type":…
2
votes
1 answer

How to handle 404 exceptions using @ControllerAdvice and @ExceptionHandler?

I have a problem with Spring's exception handling for controllers. I have a class annotated with @RestControllerAdvice with a couple of @ExceptionHandler's, like this: @ExceptionHandler(HttpRequestMethodNotSupportedException::class) fun…
hc0re
  • 1,806
  • 2
  • 26
  • 61
2
votes
2 answers

spring/hibernate validation -> error message is not passed to caller?

I am using org.springframework.boot:spring-boot-starter-validation:2.7.0(which in turn uses hibernate validator) to validate user input to rest controller. I am using Spring Boot Web Starter (2.7.0) based project with @RestController annotation My…
2
votes
3 answers

Spring Boot: RestControllerAdvice: handle wrapped exceptions

Let's say we have @RestControllerAdvice-annotated class like this: @RestControllerAdvice public class RestResponseExceptionHandler { @ExceptionHandler(MyBusinessException .class) public ResponseEntity handleMyBusinessException…
Puce
  • 37,247
  • 13
  • 80
  • 152
2
votes
1 answer

Spring ControllerAdvice global exception handler not returning response

I have a Groovy Spring Boot microservice that returns a list of posts. Requests come into the controller, the controller invokes a method in a service class, and if no posts are found, a custom error message is thrown. I've created a controller…
2
votes
3 answers

Spring - Using an exception handler from an external jar for 2 other projects

I have 2 projects that have the same exceptions and use the same exception handler. So all of the exceptions and the exception handler were moved to an external module. The exceptions are imported just fine, but the exception handler does not seem…
Rivfader
  • 59
  • 6
2
votes
1 answer

Request scoped bean exceptions and @ControllerAdvice

I have a custom Spring Boot AutoConfiguration class in which I’m creating a @RequestScoped bean of a custom class - Foo. In the same AutoConfiguration class, I’m creating a bean of my global exception handler which is a @ControllerAdvice. All these…
2
votes
1 answer

How to capture the response of ResponseEntityExceptionHandler to create JWE encrypt

I have springboot based restful web-service. I have CryptoResponseBodyAdvice to capture the response from controller and create JWE out of response body and send JWE as API response. public class CryptoResponseBodyAdvice implements…
2
votes
3 answers

Spring Dependency for ResponseEntityExceptionHandler

I am not be able to import correctly ResponseEntityExceptionHandler class ControllerAdvice @Autowired()() extends ResponseEntityExceptionHandler{ What I am missing in my pom xml file? org.springframework.boot
michele
  • 26,348
  • 30
  • 111
  • 168
2
votes
2 answers

What order value do I use on a ControllerAdvice if my libraries may also have ControllerAdvices with Order annotations that I do not know about?

I have a Spring 4 application with multiple ControllerAdvices annotated with @Order(someValue). In addition, I have discovered a ControllerAdvice in one of my external libraries also annotated with @Order(someValue). My understanding is that when a…
2
votes
1 answer

@ControllerAdvice not working Spring 5.1.6

I'm trying to implement an error handler in Spring with Kotlin, but it looks like the Application doesn't recognize it: i always get the /error page and the exception not handled. @EnableWebMvc, suggested in other similar questions, didn't work for…
1
vote
1 answer

ControllerAdvice exception handling based on URL matching

In my application I have two type of urls - /secure and /unsecure. For any exception arising from /secure/** URLs I want to do a certain type of exception handling and provide detailed error response and for /unsecure/** I want to provide a generic…
Makruzz
  • 105
  • 1
  • 7
1
vote
0 answers

Can I call a ControllerAdvice when rendering a view from an ExceptionHandler in another ControllerAdvice?

I have a ControllerAdvice that renders the requestUri to the model, since the thymeleaf upgrade (3.10) removed the #httpServletRequest attribute. @ControllerAdvice class UtilityProvider { @ModelAttribute("requestUri") fun…
peach
  • 657
  • 5
  • 26