SpringBoot打包成war包并放置在tomcat运行

1第一步

首先,我们需要将pom.xml中的打包方式改成war

<packaging>jar</packaging>
<packaging>war</packaging>

第二步

将spring-boot-starter-tomcat的scope属性设置为provided

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>

第三步

启动类上 添加ServletInitializer类

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

/**
 * 【api模块】
 *
 * @author yangjunxiong
 * @date 2021/1/5 09:18
 **/
@SpringBootApplication
@ServletComponentScan("com.yjx.project.runbatapi.web.listener")
public class RunBatApiApplication extends SpringBootServletInitializer {
    
    

第四步

在项目根目录下运行maven命令package 打包即可

猜你喜欢

转载自blog.csdn.net/qq_40250122/article/details/113104168