您好,登錄后才能下訂單哦!
這篇文章主要講解了Spring打包jar包時jsp頁面無法訪問怎么辦,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。
spring打包jar包時jsp頁面無法訪問
問題如下
當前pom.xml配置
<build> <resources> <!--引入配置文件--> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> </resource> <!--引入靜態文件--> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <filtering>false</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
解決辦法:
1.高版本的插件不支持jsp,給spring-boot-maven-plugin指定版本號“1.4.2.RELEASE”
<build> <resources> <!--引入配置文件--> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> </resource> <!--引入靜態文件--> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <filtering>false</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.2.RELEASE</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
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.
<packaging>war</packaging>
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-documentation
spring官方不推薦使用jsp,推薦使用thymeleaf、freemaker、velocity等其他模塊引擎。
看完上述內容,是不是對Spring打包jar包時jsp頁面無法訪問怎么辦有進一步的了解,如果還想學習更多內容,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。