Step1:maven项目,修改pom包
<packaging>jar</packaging> 修改成 <packaging>war</packaging>
<groupId>com.swj</groupId>
<artifactId>SpringBootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
Step2:打包时排除tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Step3:修改注册启动类
package com.swj;
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;
@SpringBootApplication
public class SpringBootDemoApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootDemoApplication.class);
}
public static void main(String[] args) {
System.out.println("我启动了...");
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
Step4:项目>右键>Run As>Maven build…
Step5:将生成的war包放到Tomcat中运行
注意:要求Tomcat8