前言
本人摸爬滚打,走过各种坑,以后会经常发布各种问题和解决方案,喜欢的下面关注评论!
第一步:排除Spring boot 自带的Tomcat 组件
<!-- 部署Tomcat容器之前,排除Spring boot 自带的Tomcat容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
第二步:修改Spring boot 启动类
这块你们直接复制粘贴就好
WhWebApplication.class,这是我的类名,改成你们自己的就OK!!
package com.transino;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class WhWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WhWebApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(WhWebApplication.class, args);
}
}
第三步:打包发布
我一般会这么从上到下点一遍
OK,把生成出来的工程名/target/XXXX.war包拷贝到Tomcat 的webapps下,启动tomcat就好了,喜欢的给个攒。