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