概述
1.Spring Boot聚合工程打包war部署Tomcat
2.Spring Boot打包Jar,通过Java -jar直接运行.
3.提供完整pom.xml测试项目 至github
4.项目目前了集成了 Spring Boot + Spring data jpa +Redis集群+dubbo+freemarker 持续更新...
解决问题
1.xxxx中没有主清单属性
2.解决没有web.xml而报错
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project provider: Error assembling WAR: webxml attribute is required(or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
版本
1.JDK 1.8
2.Spring Boot 1.5.8
3.apache-tomcat-8.5.23
一、打包war部署tomcat
1.改写App类 继承SpringBootServletInitializer
2.重写configure方法,返回builder.sources(YouApp.class);
3.添加pom.xml ,如下图
4.修改
5.package命令打包
6.可参考 github--> releases--> v0.2 中blog-main-service 它是一个可打包jar且通过java -jar运行的完整项目配置
地址:https://github.com/mmdsyl/BLOG-Microservice/releases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public
class
ManagerApplication
extends
SpringBootServletInitializer{
// for tomcat
@Override
protected
SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return
builder.sources(ManagerApplication.
class
);
}
public
static
void
main(String[] args)
throws
InterruptedException {
SpringApplication application =
new
SpringApplication(ManagerApplication.
class
);
//application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
}
|
org.springframework.boot spring-boot-starter-tomcat provided maven-war-plugin 3.0.0
二、打包Jar执行运行
1.标准的Application,不要继承SpringBootServletInitializer
2.修改pom,如图
3.package命令打包
4.可参考 github--> releases--> v0.2 中blog-main-web ,它是一个可打包war可部署tomcat中的完整配置
地址:https://github.com/mmdsyl/BLOG-Microservice/releases
1 2 3 <plugin> 4 <groupId>org.springframework.bootgroupId> 5 <artifactId>spring-boot-maven-pluginartifactId> 6 <executions> 7 <execution> 8 <goals> 9 <goal>repackagegoal> 10 goals> 11 execution> 12 executions> 13 plugin>
-END-