使用idea创建sprinboot项目默认是打jar包的配置,内嵌tomcat可直接运行程序
如果需要打war包,需要对pom.xmle文件进行配置
1.排除内嵌的tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
2,配置war包
<groupId>com.test</groupId>
<artifactId>springboot_depth_study</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
3,修改启动类
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootDepthStudyApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
这样使用mvn打包就打成war包
如果此时在idea里运行,会报错
此时可以配置tomcat运行
1,点击edit configurations
2,添加tomcat
3.点击configure
4,配置本地tomcat
5,添加artifact,
6点击确定
7,运行
8运行成功
2019-11-25 17:12:18.221 INFO 58660 --- [nio-8885-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 16 ms