Home > Net >  Exception to Context Path in Spring Boot Application
Exception to Context Path in Spring Boot Application

Time:09-30

I am building a Spring Boot and Thymeleaf application with the custom context path:

server.servlet.context-path=/myapp

So the application can be accessed as:

http://localhost:8080/myapp

All content is served on the /myapp context path, except for one mapping for a special case which needs to be:

http://localhost:8080/exception

Is there a way to make an exception to the custom context path for this special case?

CodePudding user response:

No, Context-path is globally for the whole application, but still, there are two ways to archive what you want-

  1. You can put your Context-path to all the controllers across the application manually, that way you can exclude your exception end-point from Context-path.
  2. You can create a second Dispatcher-Servlet this way you can host your other end-point on a different port.

I personally won't prefer any of the above solutions as the first one is not suitable for a large application and the second solution adds extra complexity.

  • Related