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 to be invoked. As far as I understand, the handler should be invoked from the external jar if I have the @ComponentScan annotation.
Here's how my exception handler looks like:
@ComponentScan(basePackages = {"com.*first-project*.controller",
"com.*second-project*.controller"})
@ControllerAdvice(basePackages = {"com.*first-project*.controller",
"com.*second-project*.controller"})
public class GlobalExceptionHandler {
...
}
The exception handler worked fine when it was part of each project individually. Then it only had that project's path in the @ControllerAdvice annotation and had no @ComponentScan.
The external jar with the exception handler is currently imported with:
compile files('libs/*jar-name*.jar')
Adding @Import(GlobalExceptionHandler.class) in the projects fixed the issue and the handler is being invoked properly now.