Springboot打成war包并在tomcat中运行

  1. 在pom.xml里设置
    war

2.加依赖

 
        
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        

四、修改启动类

package com.xyy.medical;

import org.mybatis.spring.annotation.MapperScan;
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;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@MapperScan("com.xyy.dao")
@ComponentScan(basePackages = {"com"})
public class MedicalApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(MedicalApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // 注意这里要指向原先用main方法执行的Application启动类
        return builder.sources(MedicalApplication.class);
    }

}

五、打包部署 mvn clean package

image.png

BUILD SUCCESS ~
打包成功

image.png

如果发现打包多了个 original结尾的war包
把pom文件的 这个注释掉就可以了

  
                
                
            

参考了
https://yq.aliyun.com/articles/319770

你可能感兴趣的:(Springboot打成war包并在tomcat中运行)