Springboot打包(二) war包
一、修改pom.xml文件打包方式改为war:
<packaging>war</packaging>
二、排除内置的Tomcat容器
方式一
<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>
方式二
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
三、启动类继承SpringBootServletInitializer实现configure:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
四、pom.xml文件中<build></build>标签下添加<finalName></finalName>标签;添加war包名称
使用外部Tomcat部署访问的时候,application.properties(或者application.yml)中配置的
server.port
server.servlet.context-path
将失效,请使用tomcat的端口,tomcat,webapps下项目名进行访问。
<build>
<finalName>war包名称</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
五、maven clean 再 install (IDEA)