简体   繁体   English

AWS Elastic Beanstalk上的Spring Boot / Tomcat仅显示404页面

[英]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. 我有一个Spring Boot应用程序,可以在Tomcat下的localhost上正常运行。 When I package it as a WAR and deploy it on Elastic Beanstalk, I only get the 404 pages. 当我将其打包为WAR并将其部署在Elastic Beanstalk上时,我只获得404页面。 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: 我已将包装配置为WAR,IntelliJ生成工件:

<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 我也把Tomcat包括在内

<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 Elastic Beanstalk服务器是运行Tomcat 8 Java 8的64位Amazon Linux 2016.03 v2.2.0

Localhost JVM is jdk1.8.0_71.jdk Localhost JVM是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. ...它会产生404错误。

I have named the .war file as Webapp.war, and as ROOT.war, and have tried accessing it at .com/ and /ROOT/ and /Webapp/ 我已将.war文件命名为Webapp.war,并将其命名为ROOT.war,并尝试在.com /和/ ROOT /和/ Webapp /中访问它

All of them produce 404. 他们都生产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. 部署后,所有文件都在/ var / lib / tomcat8 / webapps / ROOT中解压缩。

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 META-INF / MANIFEST.MF似乎很好:清单 - 版本:1.0实现 - 标题:xxxxxxxxxxx实现 - 版本:0.0.1-SNAPSHOT内置:cdc实现 - 供应商-Id:com.xxxxxxxxx创建者: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. 我一直在梳理有关AWS部署的所有其他问题,并且已经空洞。

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. 我按照mkyong https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/的说明进行操作,这似乎解决了我的问题。

Looking at your code I noticed your WebappApplication isn't extending SpringBootServletInitializer . 看看你的代码,我注意到你的WebappApplication没有扩展SpringBootServletInitializer Maybe try extending SpringBootServletInitializer like so. 也许尝试像这样扩展SpringBootServletInitializer。

@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! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Elastic Beanstalk-Tomcat Java Spring Boot应用程序出现问题 - AWS Elastic Beanstalk - Problem with tomcat java spring boot application Spring 在本地 tomcat 上工作的启动应用程序在 Elastic Beanstalk 上给出 404 - Spring boot application which works on local tomcat gives 404 on Elastic Beanstalk 如何在 Tomcat AWS Elastic beanstalk (Spring Boot Application) 中修改或添加新的 Nginx 配置 - How to modify or add new Nginx configuration in Tomcat AWS Elastic beanstalk (Spring Boot Application) AWS Beanstalk上的Spring Boot抛出404 - Spring Boot on AWS Beanstalk throwing 404 aws 弹性 beantalk 上的 HTTP 到 HTTPS 不适用于 Spring Boot - HTTP to HTTPS on aws elastic beanstalk not working for Spring Boot Spring Boot Application无法在AWS Elastic Beanstalk中进行一次身份验证 - Spring Boot Application not authenticating once in AWS Elastic Beanstalk 如何将Spring Boot应用程序大战部署到AWS Elastic Beanstalk? - How to deploy Spring Boot application war to AWS Elastic Beanstalk? 在AWS Elastic Beanstalk上部署Spring Boot应用程序 - 获得502错误 - Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error 使用自动 SSL 证书在 AWS Elastic Beanstalk 上部署 Spring Boot 应用程序 - Deploy Spring Boot application on AWS Elastic Beanstalk with automatic SSL certificates 在AWS Elastic Beanstalk上部署Spring - Deploying Spring on AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM