Spring Boot War 部署到 Tomcat [英] Spring Boot War deployed to 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}
阅读了一些pages 和 question-answers 我添加了关注我的 POM:
After reading a number of pages and question-answers I added following to my 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 package"并获得了 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屋!