简体   繁体   中英

Spring Boot / Tomcat on AWS Elastic Beanstalk only showing 404 page

I have a Spring Boot app that runs fine on my localhost under Tomcat. When I package it as a WAR and deploy it on Elastic Beanstalk, I only get the 404 pages. I have tried many different tweaks to try to get it to work but I am at a loss.

I have configured the packaging as a WAR, and IntelliJ generates the artifact:

<groupId>com.ideaEngine</groupId>
<artifactId>app_deployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <start-class>com.xxxxxxxx.WebappApplication</start-class>
    <java.version>1.8</java.version>
</properties>

I have also included Tomcat as

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

Elastic Beanstalk server is 64bit Amazon Linux 2016.03 v2.2.0 running Tomcat 8 Java 8

Localhost JVM is jdk1.8.0_71.jdk

The application object is:

@SpringBootApplication
public class WebappApplication {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebappApplication.class);
    }

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(WebappApplication.class, args);
        System.out.println("Running............");
    }
}

I have a test controller that I use to make sure everything's working:

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }
}

...and it generates 404 errors.

I have named the .war file as Webapp.war, and as ROOT.war, and have tried accessing it at .com/ and /ROOT/ and /Webapp/

All of them produce 404.

The log file shows that the app is deploying to the server:

Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 2,143 ms

All the files are unzipped in /var/lib/tomcat8/webapps/ROOT when it's deployed.

The META-INF/MANIFEST.MF seems fine: Manifest-Version: 1.0 Implementation-Title: xxxxxxxxxxx Implementation-Version: 0.0.1-SNAPSHOT Built-By: cdc Implementation-Vendor-Id: com.xxxxxxxxx Created-By: IntelliJ IDEA Build-Jdk: 1.8.0_71 Main-Class: com.xxxxxxxxx.WebappApplication

Health reads as "OK"

Environment health has transitioned from Info to Ok. Application update completed 58 seconds ago and took 15 seconds.

I've been combing all the other questions relating to deployment on AWS and have come up empty.

Again, the app runs fine on my local machine.

Any ideas as to what I'm missing?

Thanks!

So I had a similar problem to this. I followed the instructions by mkyong https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/ and that seemed to solve my problem.

Looking at your code I noticed your WebappApplication isn't extending SpringBootServletInitializer . Maybe try extending SpringBootServletInitializer like so.

@SpringBootApplication
public class WebappApplication extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebappApplication.class);
    }

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(WebappApplication.class, args);
        System.out.println("Running............");
    }
}

It's all detailed in that article. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM