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>

 

完成!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值