Tomcat Spring引导War文件在ec2上获得404

Tomcat Spring引导War文件在ec2上获得404,tomcat,amazon-ec2,spring-boot,war,Tomcat,Amazon Ec2,Spring Boot,War,我编写了一个简单的Eclipse Spring Boot Rest程序。只是返回一些字符串的两个端点。我正在使用EclipseGradle插件构建它。没有问题,它在Eclipse提供的Tomcat实例中运行良好。我还在本机windows Tomcat上运行了它。我使用部署特性使用TomcatWeb应用程序管理器部署了.war文件。运行良好。然后我部署了一个ec2 ubuntu实例,再次使用TomcatWeb应用程序管理器并上传.war文件。rest程序正确显示在“应用程序”窗口中,但不会运行。我

我编写了一个简单的Eclipse Spring Boot Rest程序。只是返回一些字符串的两个端点。我正在使用EclipseGradle插件构建它。没有问题,它在Eclipse提供的Tomcat实例中运行良好。我还在本机windows Tomcat上运行了它。我使用部署特性使用TomcatWeb应用程序管理器部署了.war文件。运行良好。然后我部署了一个ec2 ubuntu实例,再次使用TomcatWeb应用程序管理器并上传.war文件。rest程序正确显示在“应用程序”窗口中,但不会运行。我使用了下面的URL

我一直得到404的。我非常确信tomcat部署和ec2环境看起来是正确的,因为我可以在ec2实例中运行tomcat7示例,而不会出现任何问题。任何帮助都将不胜感激

awselbrestserveraaapplication.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);
    }
}
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);
    }
}
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";
    }
}
ServletInitializer.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);
    }
}
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);
    }
}
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";
    }
}
RestController.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);
    }
}
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);
    }
}
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'
}

我已经回答了一个类似的问题

您正在Java1.7JRE下运行外部tomcat,同时根据1.8编译代码

奇怪的是,没有错误,应用程序出现在manager应用程序中,但当您尝试访问它时,您会得到404

确认这一点的一种方法是查看tomcat日志输出,您不会看到Spring引导横幅


要解决这个问题,您可以针对Java 1.7编译代码。

我昨天才回答了类似的问题,可能是同一个问题吗?是的,您回答了。我刚刚将EclipseJRE更改为1.7,它成功了!默认情况下,Eclipse在项目创建菜单中选择Java1.8,但我使用的是Tomcat7。谢谢你,真是太棒了!嘿,ci_uu________________________________________。我使用JavaJRE1.8运行SpringBoot,但使用的是Tomcat7。我改为Java1.7,它工作得非常好。谢谢你的回答。