Questions tagged [controller-advice]
113 questions
1
vote
0 answers
Controller Advice for specific class/package
I am trying to limit my Controller Advice handling to only a specific package's subpackages (preferably) or a list of specific classes (I will have to manually add all classes manually this way, so it's not nearly as good). How would I go about…

Jason Chan
- 193
- 1
- 3
- 11
1
vote
1 answer
ControllerAdvice for Invalid Enums in request parameter
Controller:
@GetMapping
public Page<...> list(Pageable pageable, Filter filter){
...
}
Filter class:
@Data
@Builder
public class Filer{
private String name;
private Type type; // Enum
}
Working API calls:
/page=0&size=20…

Nagulan S
- 617
- 5
- 11
1
vote
1 answer
@ControllerAdvice or @ExceptionHandler both not working on gradle project
I have written a very simple gradle spring boot project. But non of my exception handling is working.
Tried handling at @Controller level and also at global via @ControllerAdvice, but both doesn't seems to work.
Could it be because its a gradle…

Akash Tyagi
- 97
- 2
- 15
1
vote
1 answer
Spring Boot 404 : no handler found exception in Controller Advice isn't catched
So I am trying to send a customized answer when user is trying to call an url unknown to my application. To do that I first added to my application.properties (in both main and test…

eln
- 63
- 3
- 12
1
vote
0 answers
Is it possible to have multiple ExceptionHandler in ControllerAdvice for same Exception but different web requests?
I have a task to handle all exceptions in my project via @ControllerAdvice. The project has multiple controller methods. I have a custom exception which is thrown by some of these controller methods.
For handling this exception, I have a class…

Bhupesh_decoder
- 75
- 1
- 11
1
vote
0 answers
Manage exceptions with spring @ControllerAdvice thrown in a JSF controller
Is there a way to let my custom ExceptionHandler annoted with @ControllerAdvice manage exceptions thrown in a JSF controller?
I noticed that all exceptions thrown in @PostConstruct methods won't get caught by the @ControllerAdvice class, instead JSF…

pak1989
- 11
- 2
1
vote
2 answers
Package/Endpoint/Controller Layer Exception Handling Design
So here is my requirement to handle component/package-specific exceptions. for example for package A, BAD Request should return spring default bad request-response, but for package B it should return custom response.

Yogeen Loriya
- 589
- 2
- 5
1
vote
1 answer
Ho can I make the specific exception's ExceptionHandler code to work instead of the code to handle "Exception" with @ControllerAdvice
I'm using @ControllerAdvice in Spring Boot project to handle Stripe's Card Exception but every time when this exception is thrown the code to handle Exception works instead of the code to handle specific Card Exception.
this is what I am doing…

Gyanendra
- 21
- 2
1
vote
0 answers
Spring Web: ControllerAdvice
I have the simple class to catch some exceptions like this:
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(RuntimeException.class)
public ResponseEntity

MrLebovsky
- 88
- 9
1
vote
0 answers
Can Responding with a Static Object in Spring MVC REST Endpoint Cause Concurrency Issue?
Developing in Spring Boot 2.2 and using Spring MVC REST endpoint, when errors occur, I'm sending a static object from ControllerAdvice, e.g.
@RestControllerAdvice
public class MyExceptionHandler {
private static final MyObj ERROR_OBJ = new…

NuCradle
- 665
- 1
- 9
- 31
1
vote
0 answers
Handle filter exception in control advice in spring boot
Hi I have a global exception handler and I do something if exceptions occurs.But I have spring filters and spring filters cannot catch in my globalexceptionhandler.I read similar post in stackoverflow but still confused.Is there a way to catch…

Bilgehan
- 1,135
- 1
- 14
- 41
1
vote
2 answers
How to test exceptions handling in @ControllerAdvice
I currently have two ControllerAdvice in my application, I'm supposed to merge them into one.
But I need to test them before and after the merge, test the exception and the object that the controller return me.
I'm trying to make a jUnit test with…

Spialdor
- 1,475
- 5
- 20
- 46
1
vote
3 answers
How to throw and detect this exception correct
I'm using @ControllerAdvice to detect exceptions that are thrown in the application.
Trying to throw exception during creation of a class:
public void setStatus(String status) throws InvalidInputStatusException{
…

robinmanz
- 361
- 1
- 5
- 17
1
vote
1 answer
@ControlerAdvice not working in spring boot (latest)
I try to intercept custom exception with @ControllerAdvice annotation.
This is code:
@ControllerAdvice(basePackages = "{com.ciro.cotroller}")
@RestController
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
…

ciro
- 771
- 1
- 8
- 30
1
vote
0 answers
Why to use @ResponseBody with @ControllerAdvice in the case of RESTServices
I am learning about global exception handling in spring boot. I have a designed a controller annotated with @RestController which has a controller method that throws an exception. I have designed another class named GlobalExceptionHandling annotated…

raman bhadauria
- 145
- 2
- 11