简体   繁体   English

Spring 引导应用程序中的上下文路径异常

[英]Exception to Context Path in Spring Boot Application

I am building a Spring Boot and Thymeleaf application with the custom context path:我正在使用自定义上下文路径构建 Spring Boot 和 Thymeleaf 应用程序:

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:所有内容都在/myapp上下文路径上提供,但特殊情况下的一个映射除外,它需要:

http://localhost:8080/exception

Is there a way to make an exception to the custom context path for this special case?有没有办法为这种特殊情况对自定义上下文路径进行例外处理?

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.您可以创建第二个 Dispatcher-Servlet,这样您就可以在不同的端口上托管其他端点。

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.我个人不会喜欢上述任何解决方案,因为第一个不适合大型应用程序,而第二个解决方案增加了额外的复杂性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM