springboot jar包 jsp頁面無法解析訪問 There was an unexpected error

springboot 項目無法解析jsp問題會出現如圖提示

There was an unexpected error 

 

具體原因是可能有很多種,但是嘗試了很多解決方案之後發現罪魁禍首竟是打包工具的版本問題;

1.首先確定有沒有依賴jsp整合jar包

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- jsp標籤庫 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

2.如果上面依賴完成基本都是打包問題了

  1.首先需要添加下面的配置使得生成jar包時 將jsp頁面放在META-INF/resources目錄下

<resource>
    <directory>src/main/webapp</directory>
    <!--springboot項目需要將webapp下頁面打包到META-INF/resources目錄下才能訪問-->
    <targetPath>META-INF/resources</targetPath>
    <includes>
        <include>**/*.*</include>
    </includes>
</resource>

  2.上面配置完成後還需要最後一個配置,也是最關鍵的一個配置  spring-boot-maven-plugin插件版本必須是1.4.2.RELEASE版本

而且必須指定啓動類,否則打包編譯報錯!

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <!--必須要是1.4.2.RELEASE  否則報錯!!!-->
    <version>1.4.2.RELEASE</version>
    <configuration>
        <!--1.4.2版本需要指定啓動類,否則報錯!!!-->
        <mainClass>com.hkd.HkdApplication</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

 

完成!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章