SpringBoot项目切换外置Tomcat服务器运行
作者:互联网
- 修改项目pom.xml配置文件
<!--0、添加打印为war包-->
<packaging>war</packaging>
<!--1、在pom中添加一条依赖,作为屏蔽SpringBoot中Tomcat容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
- 添加启动类, 注释掉SpringBoot原生启动类DemoApplication
/*2、重写父类方法configure,使SpringBoot容器以MutildataApplication类作为入口*/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class MutildataApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MutildataApplication.class, args);
}
// 用于构建war文件并进行部署
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
- 终端输入打包构建命令
- mvn clean
- mvn clean package -Dmaven.test.skip=true [OR] mvn clean install -Dmaven.test.skip=true
- 准备一台干净的Tomcat, 删除webapps目录下所有文件, 把刚才构建好的xxx.war解压至该目录下
- 例: 点击下载
- 运行查看效果
- 访问路径
http://IP地址:端口/构建的项目名称/控制器名称/方法名称
标签:SpringBoot,Tomcat,boot,springframework,外置,import,org,MutildataApplication 来源: https://www.cnblogs.com/Twittery/p/15100248.html