Spring Boot 打war包部署,打jar包
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot 打war包部署,打jar包相关的知识,希望对你有一定的参考价值。
官方文档:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
一:更改程序入口类 Application.java 使其继承SpringBootServletInitializer,并重写configure方法
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
二:更改pom.xml
<packaging>war</packaging>
三:确保内置servlet container 不会干涉发布该war包的servlet container,方案是标记内置servlet container 的依赖为provided
<dependencies>
<!-- … -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- … -->
</dependencies>
最后,将打好的war包放到tomcat下即可.
其实哪需要这么麻烦,我们创建工程的时候就可以建立war工程呀。
打成可以运行jar包
还原上面第一步的操作,在pom.xml中添加maven-plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
运行:Java -jar myapp.jar
以上是关于Spring Boot 打war包部署,打jar包的主要内容,如果未能解决你的问题,请参考以下文章