SpringBoot 如何在外部容器(tomcat)中运行
1、pom.xml文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 引入嵌入式tomcat插件 打包时,不会打包此依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 引入 servlet-api 打包时,不会打包此依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- project下面packaging标签改为 -->
<packaging>war</packaging>
<!-- 打包设置 -->
<build>
<plugins>
<!-- 打 war 包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
<finalName>uc</finalName>
</build>
2、将项目的启动类Application.java继承SpringBootServletInitializer并重写configure方法
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
3、打包:选中项目,右键 --> run as --> maven install
正文到此结束
- 本文标签: tomcat Spring Boot
- 版权声明: 本站原创文章,于2021年10月20日由丙火发布,转载请注明出处