Spring Boot War部署到Tomcat [英] Spring Boot War deployed to Tomcat

查看:118
本文介绍了Spring Boot War部署到Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to deploy a Spring Boot app to Tomcat, because I want to deploy to AWS. I created a WAR file, but it does not seem to run on Tomcat, even though it is visible.

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

Details:
0. Here is my app:

@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;
    }
}

application.properties具有以下内容:

application.properties has following:

server.port=${port:7777}

  1. 在阅读许多页面问题-答案跟随我的POM:

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

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>

我运行了"mvn软件包",并得到了WAR文件(大小为250Mb),并将其放入"webapps"文件夹中.

I ran"mvn package"and got WAR file (size 250Mb), which I put into "webapps" folder.

更新: 还有另一个参考.不确定它的用处.

Update: There is another reference. Not sure how useful it is.

推荐答案

本指南详细说明了如何在Tomcat上部署Spring Boot应用程序:
http://docs.spring.io /spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

This guide explains in detail how to deploy Spring Boot app on Tomcat:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

基本上,我需要添加以下课程:

Essentially I needed to add following class:

public class WebInitializer extends SpringBootServletInitializer {   
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(App.class);
    }    
}

我还向POM添加了以下属性:

Also I added following property to POM:

<properties>        
    <start-class>mypackage.App</start-class>
</properties>

这篇关于Spring Boot War部署到Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆