我在AWS和Spring Framework上都很新。如何将Spring引导程序部署到Amazon Elastic Beanstalk?
我已经按照Spring网站入门指南构建了a simple web program。此外,我已经使我的Elastic Beanstalk应用程序和环境运行Tomcat 8和Java 8.我正在尝试的是;
- 使用Gradle构建这个简单的程序并生成一个可执行的jar(或war)。
- 从我的Elastic Beanstalk仪表板上载'upload and deploy'按钮的可执行jar(或war)。
我现在正在使用IntelliJ,如果我双击生成的可执行文件jar,我的程序运行良好。但是,在将此jar上传到我的Elastic Beanstalk后,此程序仅生成HTTP 404错误。
我不明白的是,如果我使用Gradle'build'任务或'bootRun'任务,生成的可执行jar文件工作正常。但是,如果我通过Gradle'war'任务构建war文件并将其放在本地Tomcat上,则服务器会生成与AWS相同的HTTP 404错误。
这是我的build.gradle文件。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
classpath("org.apache.tomcat:tomcat-catalina:8.0.28")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
jar {
baseName = 'gs-authenticating-ldap'
version = '0.1.0'
}
war {
baseName = 'gs-authenticating-ldap'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
此外,我的节目只有两个Java类:src/main/java/hello/HomeController.java
和src/main/java/hello/Application.java
src/main/java/hello/HomeController.java
是:
package hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
@RequestMapping("/")
public String index() {
return "Welcome to the home page!";
}
}
src/main/java/hello/Application.java
是:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
作为总结:
- build'bootRun' - >浏览“localhost:8080”:工作正常。
- build'build' - >产生'xxx.jar(可执行文件)' - >双击执行这个jar - >浏览“localhost:8080”:工作正常
- build'build' - > produce'xxx。 jar'(可执行文件) - >上传到AWS - >浏览“xx.elasticbeanstalk.com”:HTTP 404错误
- build'war' - >产生'xxx.war' - >使用IntelliJ在本地Tomcat上运行这个war - >浏览 “本地主机:8080”:HTTP 404错误
- 构建 '战争' - >农产品 'xxx.war' - >上传到AWS - >浏览 “xx.elasticbeanstalk.com”:HTTP 404错误
我想要做的是1)在IntelliJ上开发,2)在Gradle上构建,3)在本地测试,4)在AWS上运行。请帮帮我。
如果您有任何进一步的解释或信息,请让我知道。 谢谢!
你解决了吗?我有一些基于我自己的测试的想法。 –
Beanstalk使用Nginx作为您的服务的反向代理,并且在后端默认使用端口5000。尝试在Beanstalk配置中将SERVER_PORT设置为5000。无论如何,错误应该是503 ... – charli