1、修改pom.xml,添加如下:(重点是【 <packaging>war</packaging>】)
<artifactId>vulSystem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
2、移除tomcat依赖(操作依旧在pom.xml中)
代码如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
当然这一步操作也可以更改为:添加spring-boot-starter-tomcat依赖,scope设置为provided
替代的带入如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3、让启动类继承SpringBootServletInitializer,并重写config方法,代码如下:
package cn.ihep;
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;
/**
* SpringBoot启动类
*
* @author xiaoming
*
*/
@SpringBootApplication
@MapperScan("cn.ihep.dao")
public class ApplicationEntrace extends SpringBootServletInitializer {
public static void main(String[] args) {
System.out.println("启动springboot");
SpringApplication.run(ApplicationEntrace.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builders) {
return builders.sources(ApplicationEntrace.class);
}
}
4、项目右键:
- run as ----->Maven clean
-
run as ------>Maven build
另外,请在Goals中写上:clean install ,如下图:
顺利的话,会在target目录下生成.war包。
【当然,我在Maven build的时候就出现很多jar包找不到的情况,但都是由于pom.xml文件中配置依赖的时候把<scope>test</scope>给加进去了,把它删除就Ok了】