春天引导战争文件中获取404 EC2春天、战争、文件

2023-09-11 09:25:34 作者:The、end。

我把一个简单的Eclipse春天引导休息计划。只是一对夫妇返回某些字符串端点。我建立它与Eclipse的摇篮插件。没有问题,它在Eclipse中正常运行提供了Tomcat实例。我也跑了它在本机窗口的Tomcat。我用的部署功能使用Tomcat Web应用程序管理器部署.war文件。运行良好。然后我部署一个EC2 Ubuntu的实例,并再次使用Tomcat Web应用程序管理器和上传.war文件。其余程序被正确地显示在应用程序窗口,但它不会运行。我用下面的网址,

HTTP://ec2-IP-Address/demo-0.0.1-快照/你好

我不断收到404的。我是pretty的肯定tomcat的部署和EC2环境,因为我可以运行tomcat7-例子EC2实例没有问题的出现是正确的。任何帮助将是AP preciated。

AwsElbRestServerAApplication.java文件:

 包演示;

进口org.springframework.boot.SpringApplication;
进口org.springframework.boot.autoconfigure.SpringBootApplication;
进口org.springframework.context.annotation.ComponentScan;
进口org.springframework.context.annotation.Configuration;

@SpringBootApplication
公共类AwsElbRestServerAApplication {

    公共静态无效的主要(字串[] args){
        SpringApplication.run(Aw​​sElbRestServerAApplication.class,参数);
    }
}
 

ServletInitializer.java文件:

 包演示

进口org.springframework.boot.builder.SpringApplicationBuilder;
进口org.springframework.boot.context.web.SpringBootServletInitializer;

公共类ServletInitializer扩展SpringBootServletInitializer {

    @覆盖
    保护SpringApplicationBuilder配置(SpringApplicationBuilder应用程序){
        返回application.sources(AwsElbRestServerAApplication.class);
    }
}
 
我的电脑今天突然打不开word文档,没中毒,点击word文档就出现这个界面

RestController.java文件:

 包演示

进口org.springframework.stereotype.Controller;
进口org.springframework.web.bind.annotation.RequestMapping;
进口org.springframework.web.bind.annotation.ResponseBody;

@Controller
公共类RestController {

    @RequestMapping(/你好)
    公共@ResponseBody字符串Hello(){

        返回从服务器A的问候;
    }

    @RequestMapping(/心跳)
    公共@ResponseBody字符串心跳(){

        返回服务器A仍在运行;
    }
}
 

build.gradle文件:

  buildscript {
    分机{
        springBootVersion ='1.2.4.RELEASE
    }
    库{
        mavenCentral()
    }
    依赖{
        类路径(org.springframework.boot:弹簧引导摇篮
        插件:$ {springBootVersion})
        类路径(io.spring.gradle:依赖管理
        插件:0.5.1.RELEASE)
    }
}

应用插件:Java的
应用插件:日食WTP
应用插件:观念
应用插件:春天启动
应用插件:io.spring.dependency管理
应用插件:战争

战争 {
    baseName的='示范'
    版本='0.0.1-快照
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

库{
    jcenter()
    行家{URLhttp://repo.spring.io/libs-snapshot}
}

配置{
    providedRuntime
}

依赖{
    编译(org.springframework.boot:弹簧引导起动致动器)
    编译(org.springframework.boot:弹簧引导启动遥控壳)
    编译(org.springframework.boot:弹簧引导启动-网)
    providedRuntime(org.springframework.boot:弹簧引导启动器雄猫)
    testCompile(org.springframework.boot:弹簧引导首发测试)
}

蚀 {
    类路径{
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER)
         集装箱的org.eclipse.jdt.launching.JRE_CONTAINER /
         org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType /
         JavaSE的-1.8
    }
}

任务包装(类型:包装){
    gradleVersion ='2.3'
}
 

解决方案

我已经回答过类似的问题here.

您正在运行外部的Tomcat下一个Java 1.7 JRE,而已经编译了code反对1.8。

奇怪的是,没有任何错误,并且该应用程序出现在管理应用程序,但你得到一个404,当你试图访问它。

要证实这一点的方法之一是看你的tomcat日志输出,你将看不到春天引导旗帜。

要解决这个问题,你可以编译code反对的Java 1.7。

I put together a simple Eclipse Spring Boot Rest program. Just a couple of endpoints that return some strings. I am building it with the Eclipse Gradle plug-in. No problems, it runs fine in the Eclipse provided Tomcat instance. I also ran it on a native windows Tomcat. I deployed the .war file using the tomcat web application manager using the deploy feature. Runs fine. I then deployed an ec2 ubuntu instance and again used the tomcat web application manager and upload the .war file. The rest program is correctly displayed in the applications window but it will not run. I used the following URL,

http://ec2-IP-Address/demo-0.0.1-SNAPSHOT/hello

I keep getting 404's. I am pretty sure the tomcat deployment and ec2 environment appears correct because I can run the tomcat7-examples in the ec2 instance with no issues. Any help would be appreciated.

AwsElbRestServerAApplication.java file:

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 file:

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 file:

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 file:

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'
}

解决方案

I've answered a similar question here.

You are running your external tomcat under a Java 1.7 JRE, while having compiled your code against 1.8.

Strangely, there is no error, and the app appears in the manager app, but then you get a 404 when you're trying to access it.

One way to confirm this is to look at your tomcat log output, you won't see the Spring Boot banner.

To solve this you can compile your code against Java 1.7.

 
精彩推荐
图片推荐