Questions tagged [controller-advice]
113 questions
1
vote
3 answers
Spring boot does not show custom error when exception is thrown
I am fairly new to Java/Spring domain and I am trying to utilize @ControllerAdvice in my Spring Boot application. The ControllerAdvice catches the exception but doesn't show my custom response.
following is the snap shot of RestController which is…

Karan
- 752
- 2
- 13
- 34
1
vote
0 answers
ControllerAdvice didn't catch an BindingResult errors
I'm trying to override default error messages in BindingResult. I implemented Controller advice like this
@ControllerAdvice
public final class DefaultControllerAdvice {
private static final String ERROR_MESSAGE_FORMATTER = " - ";
…

Jarek Sularz
- 67
- 8
1
vote
1 answer
How control advice catches exception
I am trying to understand how ControllerAdvice is working in SpringBoot. It is suggested that for per application there should be one ControllerAdvice. But my question is how this ControllerAdvice is tied to Controllers and catching the exceptions.…

user1474111
- 1,356
- 3
- 23
- 47
1
vote
1 answer
Spring-boot Rest : Use ControllerAdvice but keep default handlers
My basic need was to catch user defined exceptions and return generic responses. For this I used the @ControllerAdvice with @ExceptionHandler. See example below
@ControllerAdvice
public class CustomGlobalExceptionHandler extends…

Wildfire
- 162
- 2
- 16
1
vote
1 answer
How to get a full stacktrace with ControllerAdvice in Spring Boot?
I use a @ControllerAdvice for my REST service. However I can not get a full stacktrace and define where an exception occured.
My ControllerAdvice:
@ControllerAdvice
public class RestResponseEntityExceptionHandler
extends…

Kirill Ch
- 5,496
- 4
- 44
- 65
1
vote
1 answer
MockMvc and @ControllerAdvice doesn't work in tests
I'm testing my RestController with mockMvc. I have a global RestExceptionHandler to resolve all exceptions. In my RestController I throw custom Exception RequestValidationException like this:
@ApiOperation("Search something")
…

Хамидилло Мамытов
- 110
- 3
- 14
1
vote
1 answer
@ControllerAdvice, how to get the class which called this method?
Is there a way to get the class from where the @ControllerAdvice got its control.
I.e.: If and execution of PersonController is going on and I get some error due to which the control transferred to the @ControllerAdvice class's method…

Bilbo Baggins
- 2,899
- 10
- 52
- 77
0
votes
0 answers
Short messages for MethodArgumentNotValidException
Got a simple DTO for users of my app where I use jakarta validators for the length of the password.
public class UserDto {
@NonNull
@NotBlank private String username;
@JsonProperty(access = WRITE_ONLY)
@NonNull
@ToString.Exclude
…

Jason
- 2,495
- 4
- 26
- 37
0
votes
0 answers
Use the same ControllerAdvice in a parent module of a microservice architecture
Is it considered as a best practise if we put the same controllerAdvice in the parent project of our microservice architecture. In fact we can throw only two runtime exceptions (FunctionalException and TechnicalException). Both of them are also in a…

Mahdi Ezzaouia
- 31
- 4
0
votes
1 answer
Why Exception is caught within Spring Boot Controller by @ExceptionHandler but not by @ExceptionHandler in @ControllerAdvice?
In a Spring Boot MVC application I have a controller which calls a service method:
@Controller
@RequestMapping("/registration")
public class RegistrationController {
@GetMapping({"/email-confirmation"})
public String…

Slevin
- 617
- 1
- 7
- 17
0
votes
1 answer
[SpringBoot]: Decorating exception when deserializing @RequestBody
I've got a DTO that represents bank accounts:
@Data
@AllArgsConstructor
public class AccountDto {
@NonNull
private String id;
@NonNull
private Long balance;
@NonNull
private Currency currency;
}
Currency is an enum where…

Jason
- 2,495
- 4
- 26
- 37
0
votes
0 answers
Spring Access Parameter Annotation Value in Rest Controller Advice
Is it possible to access parameter annotation value in restcontroller advice.In my case MyApiRequest is not valid for that reason I got 400 error.In restcontrolleradvice I catch this error and Also want some logging with myparameter value.But I cant…

Bilgehan
- 1,135
- 1
- 14
- 41
0
votes
0 answers
Do I need to handle org.springframework.validation.BindException if I am already handling org.springframework.web.bind.MethodArgumentNotValidException
I am trying to write Control Advice and I want to keep similiar exception handling accross different services. My question is do I need to handle org.springframework.validation.BindException if I am already handling…

Saurabh Gadariya
- 191
- 6
- 20
0
votes
0 answers
Spring RestControllerAdvice status code 304 NOT MODIFIED Does not return the body I command
I think this behaviour is correct, because reading from here it says: "HTTP response status code 304 Not Modified is returned by the server to indicate a successful HTTP request, yet there is no need to send the data associated with the relevant…

BugsOverflow
- 386
- 3
- 19
0
votes
1 answer
Springboot NoHandlerFoundException weird URL pattern issue
Apologies, I really cannot share the whole code , but will try my best to explain the issue.
I am trying to catch NoHandlerFoundException in Controller Advice with following code :
Controller Advice Code…

Manik_Vashisht
- 71
- 1
- 4