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

部署Elastic Beanstalk(Tomcat)时无法加载首页问题

Troubleshooting Elastic Beanstalk Spring Boot Static Resource Issue

Hey there, let's tackle this weird problem you're having with your Spring Boot app on Elastic Beanstalk. I've run into similar quirks before, so let's walk through some actionable fixes step by step:

  • Verify static resource placement in your project
    Spring Boot automatically looks for static files (like index.html) in specific directories: src/main/resources/static, src/main/resources/public, or src/main/resources/resources. If you placed index.html directly in the root of your war file, Tomcat + Spring Boot won't pick it up by default. Double-check your local project structure—make sure index.html lives in one of those standard static resource folders, then repackage and redeploy your war.

  • Ensure your war uses the ROOT context
    Elastic Beanstalk's Tomcat environment maps war files to contexts based on their filename. If your war is named something like socialnotes-snapshot.war, Tomcat will serve it under http://your-url/socialnotes-snapshot/ instead of the root path. To fix this:

    1. Rename your war file to ROOT.war before deploying
    2. Or, in your Elastic Beanstalk environment configuration, set the application context path to / (under "Software" settings)
  • Check your Spring Boot entry class configuration
    For war deployment, your main application class must extend SpringBootServletInitializer and override the configure method to properly bootstrap the Spring context in Tomcat. Here's what that should look like:

    @SpringBootApplication
    public class SocialNotesApplication extends SpringBootServletInitializer {
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(SocialNotesApplication.class);
        }
    
        public static void main(String[] args) {
            SpringApplication.run(SocialNotesApplication.class, args);
        }
    }
    

    If you skipped this step, your Spring context might not initialize correctly, leading to missing static resources.

  • Dig into Elastic Beanstalk logs
    Logs are your best friend here. Head to your Elastic Beanstalk environment dashboard, go to "Logs" and request the full log bundle. Look for:

    • Tomcat's catalina.log or localhost.log for 404 errors related to index.html
    • Spring Boot initialization logs to confirm the context loaded successfully
      You can also SSH into the EC2 instance and check logs directly at /var/log/tomcat/ for real-time insights.
  • Test direct file access and clear browser cache
    Sometimes browser cache can trick you into thinking the page isn't loading. Try accessing http://socialnotes-env-tomcat.eu-west-1.elasticbeanstalk.com/index.html directly (with the filename) in an incognito window to rule out caching issues.

Give these steps a shot—one of them should resolve that frustrating missing index.html issue. If you're still stuck, sharing snippets of your project structure or relevant log lines would help narrow things down further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:34:59