Search code examples
spring-bootmicroservices

Can I put the exception handler of the microservices in an independent service?


I have a microservices architecture using spring boot with a couple of services and one base service that the services use as jar. Can I put the exception handler for the whole project in the base service or should each service have its own exception handler ? If yes, does the base service need to be a spring boot application and should it be running ?


Solution

  • Yes, you can include the exception handler inside your base service and it doesn't need to be a springboot application, all you have to do is create a @Configuration class inside your other services and load the class of the base service where you have defined your exception handler.

    something line this:

    @Configuration
    @Import({ ExceptionHandler.class })