4

我有一个Spring Boot应用,可以在Tomcat下的本地主机上正常运行。当我将它打包为WAR并将其部署到Elastic Beanstalk时,我只能获得404页面。我尝试了许多不同的调整,试图让它起作用,但我无所适从。AWS上的Spring Boot/Tomcat Elastic Beanstalk只显示404页面

我已经配置了包装成一个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> 

我也包括Tomcat作为

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

弹性豆茎服务器为64bit亚马逊的Linux 2016.03 V2.2.0运行Tomcat 8 Java 8

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............"); 
    } 
} 

我有使用,以确保一切的工作测试控制器:

@RestController 
public class HelloController { 

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

...和它产生404错误。

我有一个名为.war文件作为Webapp.war,并作为ROOT.war,并试图在.COM /和/ ROOT /和/的webapp/

他们全部产生404

访问它

日志文件显示,该应用被部署到服务器:

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

所有文件都在/ var解压/ lib中/ tomcat8时,它的部署/ webapps /目录ROOT。

的META-INF/MANIFEST.MF似乎罚款: 清单-版本:1.0 实现-标题:XXXXXXXXXXX 的实现版本:0.0.1-SNAPSHOT 内置者:CDC 实现厂商ID: com.xxxxxxxxx 创建-者:IntelliJ IDEA的 内建的jdk:1.8.0_71 主类:com.xxxxxxxxx.WebappApplication

生读作 “OK”

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

我一直在梳理与AWS上的部署有关的所有其他问题,并且已经空了。

同样,应用程序在我的本地机器上运行良好。

任何想法,我失踪了?

谢谢!

+0

我遇到了同样的问题,队友。你有没有想出一个解决方案? – LynchburgExplorer

回答

1

所以我有类似的问题。我遵循mkyong https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/ 的说明,似乎解决了我的问题。

看你的代码,我注意到你的WebappApplication没有延长SpringBootServletInitializer。也许尝试像这样扩展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............"); 
    } 
} 

这一切都在那篇文章中详细介绍。希望这可以帮助!