我想将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; } }
application.properties具有以下内容:
application.properties
server.port=${port:7777}
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”文件夹中。
我启动了Tomcat,并能够看到列出的应用程序,在本例中为“ /highlighter-1.0-SNAPSHOT”。
本质上,我需要添加以下类:
public class WebInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(App.class); } }
我还向POM添加了以下属性:
<properties> <start-class>mypackage.App</start-class> </properties>