其他分享
首页 > 其他分享> > SpringBoot项目切换外置Tomcat服务器运行

SpringBoot项目切换外置Tomcat服务器运行

作者:互联网

  1. 修改项目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>
  1. 添加启动类, 注释掉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());
    }
}
  1. 终端输入打包构建命令
  1. 准备一台干净的Tomcat, 删除webapps目录下所有文件, 把刚才构建好的xxx.war解压至该目录下
  1. 运行查看效果

标签:SpringBoot,Tomcat,boot,springframework,外置,import,org,MutildataApplication
来源: https://www.cnblogs.com/Twittery/p/15100248.html