![](/img/trans.png)
[英]AWS Elastic Beanstalk - Problem with tomcat java spring boot application
[英]Spring Boot / Tomcat on AWS Elastic Beanstalk only showing 404 page
我有一個Spring Boot應用程序,可以在Tomcat下的localhost上正常運行。 當我將其打包為WAR並將其部署在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>
Elastic Beanstalk服務器是運行Tomcat 8 Java 8的64位Amazon Linux 2016.03 v2.2.0
Localhost JVM是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 Build-Jdk:1.8.0_71 Main-Class:com.xxxxxxxxx.WebappApplication
健康讀作“好”
Environment health has transitioned from Info to Ok. Application update completed 58 seconds ago and took 15 seconds.
我一直在梳理有關AWS部署的所有其他問題,並且已經空洞。
再次,該應用程序在我的本地計算機上運行良好。
關於我缺少什么的任何想法?
謝謝!
所以我遇到了類似的問題。 我按照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............");
}
}
這篇文章中都詳細介紹了這一點。 希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.