Springboot的 server.context-path 和 server.servlet-path 的区别


首先说一下 server.context-path ,它代表的是应用上下文根

server.context-path=/xiaomaomao

例如我在 application.properties 中配置了 server.context-path=/xiaomaomao ,那么我访问服务端资源的时候就必须加上 /xiaomaomao

例如:你要访问到这个 Controller 中的 /hello 映射,那么你浏览器发起的请求就要是 http://localhost:8080/xiaomaomao/hello

@Controller
public class SpringbootErrorController {
    @RequestMapping("/hello")
    public void error01() {
        System.out.println("hello world");
    }
}

而对于 server.servlet-path 来说,它代表的是 DispatcherServlet 的拦截路径

server.servlet-path=/xiaomaomao

这里配置的 DispatcherServlet 拦截路径就是 /xiaomaomao,但是我们配置 DispatcherServlet 都是使用默认的路径 / (拦截所有请求,不拦截 jsp)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;springboot无法注入,注入后无效 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 异常 java的swagger跟servlet的context-path使用坑 org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [WebApp] in context with path关于数据库库的问题 springboot admin 集成nacos, context-path导致的问题解决 报错:严重: Servlet.service() for servlet [jsp] in context with path [/20161116-Struts2-6] threw exception [/index.jsp (line: 13, column: 20) No tag "textfiled" defined in tag library imported with prefix 错误:严重: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is Servlet.service() for servlet [dispatcherServlet] in context with path [/heima_ssm_web] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Unable to compile class for JSP] with root cause java.lang.IllegalArgumentException: Page directive: inval 报错更改 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] wit
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM