I created a class MyExceptionHandler
annotated with @ControllerAdvice
and @ResponseBody
to handle Exceptions, as it is a common practice in Spring Boot.
Now I moved this class to a starter, that I include in several projects, so they all use the same basic exception handling. This works fine, when I start the Spring Boot application normally.
When I execute a test annotated with:
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@WebMvcTest(controllers = SomeController.class)
The ControllerAdvice from the starter is not activated, so I can't test my error responses.
When I create a subclass of MyExceptionHandler
in my project and annotate that class with @ControllerAdvice
and @ResponseBody
, everything works fine.
How can I ensure, that during my test, the ControllerAdvice from the starter is activated?