AWS Elastic Beanstalk上的Spring Boot/Tomcat仅显示404页面 [英] Spring Boot / Tomcat on AWS Elastic Beanstalk only showing 404 page

查看:159
本文介绍了AWS Elastic Beanstalk上的Spring Boot/Tomcat仅显示404页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序,可以在Tomcat下的本地主机上正常运行.当我将其打包为WAR并将其部署在Elastic Beanstalk上时,我只会得到404页.我尝试了许多不同的调整来尝试使其正常工作,但我很茫然.

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.

我已经将包装配置为WAR,并且IntelliJ生成了工件:

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>

我也将Tomcat包含为

I have also included Tomcat as

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

Elastic Beanstalk服务器是运行Tomcat 8 Java 8的64位Amazon Linux 2016.03 v2.2.0

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

Localhost JVM是jdk1.8.0_71.jdk

Localhost JVM is jdk1.8.0_71.jdk

应用程序对象是:

@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!";
    }
}

...并且它会产生404错误.

...and it generates 404 errors.

我已将.war文件命名为Webapp.war和ROOT.war,并尝试通过.com/和/ROOT/和/Webapp/

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

所有人都产生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

所有文件在部署后都在/var/lib/tomcat8/webapps/ROOT中解压缩.

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

META-INF/MANIFEST.MF看起来不错: 清单版本:1.0 实施标题:xxxxxxxxxxx 实施版本:0.0.1-SNAPSHOT 内建:cdc 实施-供应商ID:com.xxxxxxxxx 创建者:IntelliJ IDEA Build-Jdk:1.8.0_71 主要类别:com.xxxxxxxxx.WebappApplication

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.

我一直在整理与在AWS上进行部署有关的所有其他问题,并且空无一物.

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?

谢谢!

推荐答案

所以我有与此类似的问题.我按照mkyong的指示 https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/ 那似乎解决了我的问题.

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.

查看您的代码,我发现您的 WebappApplication 没有扩展 SpringBootServletInitializer .也许尝试像这样扩展SpringBootServletInitializer.

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!

这篇关于AWS Elastic Beanstalk上的Spring Boot/Tomcat仅显示404页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆