You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot+JSP应用重启后报ClassNotFoundException问题求助

解决SpringBoot JSP部署后ClassNotFoundException问题

排查方向及解决方法

  • 修正Maven打包配置
    确保pom.xml里JSP相关依赖和打包配置正确,避免依赖缺失或JSP文件未被打包进WAR:

    <dependencies>
        <!-- JSP核心依赖,部署外部服务器时不要设为provided -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>compile</scope>
        </dependency>
        <!-- JSTL依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
        <!-- 确保JSP文件被打包到正确位置 -->
        <resources>
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/*.jsp</include>
                </includes>
            </resource>
        </resources>
    </build>
    
  • 清理服务器JSP编译缓存
    以Tomcat为例,找到服务器的work目录(比如Tomcat/work/Catalina/localhost/你的应用名),删除该目录下的所有文件,然后重启服务器,让服务器重新编译JSP文件。

  • 验证WAR包完整性
    手动解压Jenkins生成的WAR包,检查:

    • WEB-INF/views下是否存在homePage.jsp
    • WEB-INF/lib中是否有tomcat-embed-jasper.jar和jstl.jar
    • JSP文件路径和代码中视图解析器配置的路径一致
  • 检查SpringBoot视图配置
    确认application.properties或application.yml里的视图解析器配置正确:

    spring.mvc.view.prefix=/WEB-INF/views/
    spring.mvc.view.suffix=.jsp
    
  • 确认服务器权限
    确保应用服务器进程对WAR解压后的目录、服务器work目录有读写权限,权限不足会导致JSP无法编译生成class文件。

内容的提问来源于stack exchange,提问作者Zulu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 02:11:00