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>
完成!!!