我编写了一个简单的程序。只是几个返回字符串的端点。我正在用Eclipse Gradle插件构建它。没有问题,它在Eclipse提供的Tomcat实例中运行良好。我还在一个本地窗口Tomcat上运行它。我使用tomcat应用程序管理器使用部署特性部署了.war文件。跑得很好。然后我部署了一个ec2 ubuntu实例,并再次使用tomcat应用程序管理器并上传了.war文件。rest程序在“应用程序”窗口中正确显示,但不会运行。我使用了以下URL,
http://ec2-IP-Address/demo-0.0.1-SNAPSHOT/hello
我一直得到404,我很确定tomcat部署和ec2环境看起来是正确的,因为我可以在ec2实例中运行tomcat 7示例,没有任何问题。任何帮助都将不胜感激。
AwsElbRestServerAApplication.java文件:
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
public class AwsElbRestServerAApplication {
public static void main(String[] args) {
SpringApplication.run(AwsElbRestServerAApplication.class, args);
}
}ServletInitializer.java文件:
package demo
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AwsElbRestServerAApplication.class);
}
}RestController.java文件:
package demo
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class RestController {
@RequestMapping("/hello")
public @ResponseBody String hello() {
return "Greetings from Server A";
}
@RequestMapping("/heartbeat")
public @ResponseBody String heartbeat() {
return "Server A is still running";
}
}build.gradle文件:
buildscript {
ext {
springBootVersion = '1.2.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle
plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management
Plugin:0.5.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-remote-shell")
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/
org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/
JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}发布于 2015-06-21 10:17:51
我回答了一个类似的问题,here。
您正在Java1.7JRE下运行外部tomcat,同时使用1.8编译代码。
奇怪的是,没有错误,应用程序出现在管理应用程序中,但是当你试图访问它时,你会得到404。
确认这一点的一种方法是查看tomcat日志输出,您将不会看到Spring横幅。
要解决这个问题,可以使用Java1.7编译代码。
https://stackoverflow.com/questions/30929098
复制相似问题