如何解决Spring Boot War部署到Tomcat
本质上,我需要添加以下类:
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>
解决方法
我想将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
具有以下内容:
server.port=${port:7777}
- 阅读了许多页面和问题后,我在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>
-
我运行了“ mvn软件包”,并得到了WAR文件(大小为250Mb),并将其放入“ webapps”文件夹中。
-
我启动了Tomcat,并能够看到列出的应用程序,在本例中为“ /highlighter-1.0-SNAPSHOT”。
- 单击应用程序的链接将显示“状态404”页面。
- 当我单独运行Spring Boot应用程序而没有容器时,它运行在localhost:7777上,但是当我在Tomcat中运行它时却什么也没有。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。