1.编辑pom.xml文件下的packaging为war,
<packaging>war</packaging>
2.移除内嵌tomcat
<exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions>
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);}@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {// 注意这里要指向原先用main方法执行的Application启动类return builder.sources(UserPerson4Application.class);}}