相关疑难解决方法(0)

Spring Boot War部署到Tomcat

我正在尝试将Spring Boot应用程序部署到Tomcat,因为我想部署到AWS.我创建了一个WAR文件,但它似乎不在Tomcat上运行,即使它是可见的.

详细信息:
0.这是我的应用程序:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class App {
    public static void main(String[] args) {
        SpringApplication.run(SampleController.class, args);
    }
}

@Controller
@EnableAutoConfiguration
public class SampleController {
    @RequestMapping("/help")
    @ResponseBody
    String home() {
        String input = "Hi! Please use 'tag','check' and 'close' resources.";
        return input;
    }
}
Run Code Online (Sandbox Code Playgroud)

application.properties有以下内容:

server.port=${port:7777}
Run Code Online (Sandbox Code Playgroud)
  1. 在阅读了许多页面问题后,我在POM中添加了以下内容:

    http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

    <groupId>com.niewlabs</groupId>
    <artifactId>highlighter</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <packaging>war</packaging>
    
    <properties>
        <java.version>1.8</java.version>
    </properties>    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.9.RELEASE</version>
    </parent>    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
    Run Code Online (Sandbox Code Playgroud)

  2. 我运行了"mvn package"并获得了WAR文件(大小为250Mb),我将其放入"webapps"文件夹中. …

spring tomcat maven spring-boot

70
推荐指数
5
解决办法
10万
查看次数

Spring Boot War文件在ec2上获得404

我整理了一个简单的Eclipse Spring Boot Rest程序.只有几个返回一些字符串的端点.我正在使用Eclipse Gradle插件构建它.没有问题,它在Eclipse提供的Tomcat实例中运行良好.我也在原生Windows Tomcat上运行它.我使用部署功能使用tomcat Web应用程序管理器部署了.war文件.运行很好.然后我部署了一个ec2 ubuntu实例,并再次使用tomcat Web应用程序管理器并上传.war文件.其余程序正确显示在应用程序窗口中,但不会运行.我使用了以下网址,

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

我一直在买404.我很确定tomcat部署和ec2环境看起来是正确的,因为我可以在ec2实例中运行tomcat7-examples而没有任何问题.任何帮助,将不胜感激.

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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() { …
Run Code Online (Sandbox Code Playgroud)

tomcat war amazon-ec2 spring-boot

2
推荐指数
1
解决办法
3746
查看次数

标签 统计

spring-boot ×2

tomcat ×2

amazon-ec2 ×1

maven ×1

spring ×1

war ×1