springboot jsp 打jar包 访问404问题

注意点:

1,关于插件spring-boot-maven-plugin的版本,目前测试结果是只有1.4.2.RELEASE可以成功。

2,关于resources设置

 

 

我的问题是在:resources设置

错误的配置如下

    <resource>

     <directory>src/main/java</directory>
      </resource>
      <resource>
      <directory>src/main/resources</directory>
      </resource>
      <resource>
     <directory>src/main/webapp</directory>

打包后目录

 

本来static和WEB-INF目录应该在 META-INF下的,但是放到了BOOT-INF目录下访问就出错了!!

后来将pom修改为 

<build>
    <plugins>
        <!-- 使用spring boot的maven插件进行打包 -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.4.2.RELEASE</version>
    
        </plugin>
    </plugins>
    <resources>
                       <!-- 打包时将jsp文件拷贝到META-INF目录下-->
            <resource>
                <!-- 指定resources插件处理哪个目录下的资源文件 -->
                <directory>src/main/webapp</directory>
                <!--注意此次必须要放在此目录下才能被访问到-->
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/**</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
</resources>
</build>
之前没有红色字体的配置,导致打包后jar包里面的META-INF目录下没有静态资源,所以访问出现404!

打包后的目录如下

 

 

页面就可以正常访问到了! 
————————————————
版权声明:本文为CSDN博主「青春不羁88」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40575726/article/details/87984027