1.使用Maven将Springboot项目打成jar包,默认是不会将WEB-INF目录下的文件打包进去的,因此,需要在pom.xml文件当中添加如下配置:
<resources>
<resource>
<!-- 指定resources插件处理哪个目录下的资源文件 -->
<directory>${basedir}/src/main/webapp</directory>
<!-- 需要将资源文件放到该目录下才能访问 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
2.版本问题,当不是1.4.2的时候,就会出现无法访问的问题
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
</plugin>
</plugins>
完整配置如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
</build>