byr*_*1st 4 java spring tomcat amazon-web-services
我在AWS和Spring Framework上都很新.
我在Spring网站的入门指南之后构建了一个简单的Web程序.此外,我已经使我的Elastic Beanstalk应用程序和环境运行Tomcat 8和Java 8.我正在尝试的是;
我现在正在使用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'
}
Run Code Online (Sandbox Code Playgroud)
此外,我的程序只有两个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!";
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
作为总结:
我想要做的是1)在IntelliJ上开发,2)在Gradle上构建它,3)在本地测试它,4)将它上传到AWS上运行.请帮我.
如果您有任何进一步的解释或信息,请告诉我.谢谢!
我有一个类似的问题,你需要做的是首先使你的Application类扩展SpringBootServletInitializer:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
它将使用Spring Framework的Servlet支持初始化您的应用程序(Tomcat将能够注册servlet并启动应用程序).
然后,您必须告诉Gradle应用程序服务器将提供环境运行时.为此,在依赖项下添加以下行:
dependencies {
// …
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
// …
}
Run Code Online (Sandbox Code Playgroud)
构建一个新的war(build war)并部署它.
有关更多信息,请参阅有关如何将Spring Boot应用程序部署为战争的文档:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html
| 归档时间: |
|
| 查看次数: |
3820 次 |
| 最近记录: |