spring打包jar包時jsp頁面無法訪問
問題如下
當前pom.xml配置
src/main/resourcesfalsesrc/main/webappMETA-INF/resourcesfalseorg.springframework.bootspring-boot-maven-pluginorg.apache.maven.pluginsmaven-surefire-plugintrue
解決辦法:
1.高版本的插件不支持jsp,給spring-boot-maven-plugin指定版本號“1.4.2.RELEASE”
src/main/resourcesfalsesrc/main/webappMETA-INF/resourcesfalseorg.springframework.bootspring-boot-maven-plugin1.4.2.RELEASEorg.apache.maven.pluginsmaven-surefire-plugintrue
2.根據spring官網說明,可打包war包,仍然可使用jar -jar xxx.war執行。
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations
JSP Limitations When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support. With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar. Undertow does not support JSPs. Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-documentation
spring官方不推薦使用jsp,推薦使用thymeleaf、freemaker、velocity等其他模塊引擎。
[月球人 ] Spring打包jar包時jsp頁面無法訪問問題解決已經有266次圍觀