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

Spring Boot部署远程服务器出现JSP页面404未找到问题求助

Spring Boot JSP 404 After Jar Deployment on Ubuntu Server

Hey, I’ve run into this exact headache before—Spring Boot’s default jar packaging doesn’t play nicely with JSPs, which is why everything works locally in IDEA but breaks when you deploy the jar to your DigitalOcean server. Let’s break down the fixes step by step:

Why this happens

Spring Boot’s embedded Tomcat handles JSPs differently when running from a jar vs. in your IDE. When you build a jar, the JSP files aren’t packaged into a directory the embedded server can access at runtime—they get tucked away in a place the view resolver can’t find.

Fix 1: Switch to WAR packaging (most reliable)

This is the standard, foolproof solution for JSP-based Spring Boot apps:

  • Update your pom.xml to set packaging to war:
    <packaging>war</packaging>
    
  • Mark the embedded Tomcat dependency as provided so it doesn’t conflict with the full Tomcat instance on your server:
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    
  • Make your main application class extend SpringBootServletInitializer to enable WAR deployment compatibility:
    @SpringBootApplication
    public class YourAppApplication extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(YourAppApplication.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(YourAppApplication.class, args);
        }
    }
    
  • Build the war with mvn clean package, then upload it to your Ubuntu server’s Tomcat webapps directory. Start Tomcat, and your JSPs will be accessible at http://your-server-ip:8080/your-app-name/home.

Fix 2: Adjust JSP location for jar packaging (less reliable)

If you really want to stick with a jar deployment, you need to move your JSPs to a location the embedded Tomcat can find inside the jar:

  • Move all your JSP files from src/main/webapp/WEB-INF/jsp/ to src/main/resources/META-INF/resources/WEB-INF/jsp/
  • Keep your application.properties configuration unchanged:
    spring.mvc.view.prefix: /WEB-INF/jsp/
    spring.mvc.view.suffix: .jsp
    
  • Build and run the jar as usual with java -jar your-app.jar. Note that this method has compatibility quirks with some Spring Boot versions, so WAR is still the safer bet.

Quick verification checks

  • Use jar tf your-app.jar on your server to confirm your JSP files exist in the expected directory. If they’re missing, your build configuration is the issue.
  • Check server logs (run tail -f logs/spring.log or similar) for view resolution errors—this will confirm if the server is even trying to locate the JSPs.
  • Double-check your access URL: for jar deployments, it’s http://your-server-ip:8080/home; for WAR deployments, you need to include the app name (e.g., http://your-server-ip:8080/your-app-war-name/home).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:39:02