这里卡了点时间,试了集中方法,最后把可行的拿出来。
- 将pom.xml中的jar包改为war包,
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging><!--<packaging>jar</packaging>-->
- 1
- 2
- 3
- 4
并添加如下一个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
- 1
- 2
- 3
- 4
- 5
2 将DemoApplication修改如下:
package com.example;
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.web.WebApplicationInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
前两步摘抄自:https://blog.csdn.net/MT_xiaoshutong/article/details/54019993
3.点击左下角的
选择Maven Projects
接着直接打包
OK