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

React+SpringBoot打包War部署Tomcat遇白标错误求助

React + SpringBoot 打包成War后部署Tomcat出现白标错误

我需要把React前端和SpringBoot后端打包成单个War文件,部署到Tomcat(内置/外置均可)。

项目文件夹结构:
项目文件夹结构

我使用的Gradle构建任务如下:

node {
    download=false
    workDir = file("${project.projectDir}/frontend/nodejs")
    npmWorkDir = file("${project.projectDir}/frontend/npm")
    nodeModulesDir = file("${project.projectDir}/frontend")
}

task appNpmInstall(type: NpmTask){
    description = " read packge.json and install all jars"
    workingDir = file("${project.projectDir}/frontend")
    args =["install"]
}

task appNpmBuild(type: NpmTask){
    description = "Builds applciation for your frontend "
    workingDir = file("${project.projectDir}/frontend")
    args =["run", "build"]
}

task copyToFrontend(type: Copy){
    from "$projectDir/frontend/build"
    into "$buildDir/resources/main/static"
}

appNpmBuild.dependsOn appNpmInstall
copyToFrontend.dependsOn appNpmBuild
compileJava.dependsOn copyToFrontend

打包后已验证War包内WEB-INF->classes下存在static文件夹:
War包内static文件夹验证

我尝试了两种部署方式:

  • 内置Tomcat:java -jar build/libs/automation.war
  • 外置Tomcat部署

但访问localhost:8080或localhost:8080/index.html时,均出现白标错误页面:
白标错误页面

日志中报错信息:

2024-11-11 15:55:00.072  WARN 11844 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "index.html"]

有没有遇到过这类问题的?求可行的解决方案,我可以提供更多细节。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 09:41:12