SpringBoot下MVC(JSP开发)打包成jar后页面404的解决办法

2021-08-05 572点热度 0人点赞 0条评论

SpringBoot下MVC整合(包含JSP页面以及JSTL)请看:https://blog.terrynow.com/2021/07/07/springboot-mvc-jsp-and-jstl-implment/

SpirngBoot开发环境下正常,本次我们不准备打包成war包放到tomcat下运行,而是打包成jar后,直接java -jar xxx.jar 运行起来,打开页面报错404

原因是正常的maven package后,maven并没有把src/main/webapp下的资源文件、jsp等文件打包进jar相应的目录

经过一番搜索,找到了解决办法,记录如下,供参考

修改pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/webapp</directory>
            <targetPath>META-INF/resources</targetPath>
            <includes>
                <include>**/**</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/**</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!-- must use 1.4.2 version -->
            <version>1.4.2.RELEASE</version>
        </plugin>
    </plugins>
</build>

原文链接 https://stackoverflow.com/questions/22121918/package-a-spring-boot-application-including-jsps-and-static-resources

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论