idea下springboot导出war包

1.编辑pom.xml文件下的packaging为war,

<packaging>war</packaging>

idea下springboot导出war包_第1张图片

2.移除内嵌tomcat

           <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>

idea下springboot导出war包_第2张图片

3.修改启动类,继承SpringBootServletInitializer类, 新增configure方法

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.support.SpringBootServletInitializer;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@MapperScan("com.example.mapper")//与dao层的@Mapper二选一写上即可(主要作用是扫包)
public class UserPerson4Application extends SpringBootServletInitializer{
     
    public static void main(String[] args) {
     
        SpringApplication.run(UserPerson4Application.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
     
       // 注意这里要指向原先用main方法执行的Application启动类
       return builder.sources(UserPerson4Application.class);
    }
}

4.点击build->build artified->选择自己需要的war,等一会就好了

你可能感兴趣的:(idea下springboot导出war包)