SpringBoot项目生成War包
来源:互联网 发布:淘宝小二电话 编辑:程序博客网 时间:2024/06/11 03:28
Spring Boot 项目默认生成Jar包,如果想发布到Tomcat还需要生成War包才能运行,SpringBoot官方文档中已经阐述了具体的操作方法,可以参考:howto-create-a-deployable-war-file;
以下使用Gradle作为Build工具
1. 向build.gradle文件添加依赖
- build.gradle
buildscript { ext { springBootVersion = '1.5.4.RELEASE' }// repositories {// mavenCentral()// } repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }}apply plugin: 'java'apply plugin: 'war' // 生成war包apply plugin: 'eclipse'apply plugin: 'org.springframework.boot'version = ''sourceCompatibility = 1.8//repositories {// mavenCentral()//}repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }}dependencies { compile('org.springframework.boot:spring-boot-starter-data-redis') compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0') compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-aop') compile('org.springframework.boot:spring-boot-starter-actuator') runtime('com.h2database:h2') runtime('mysql:mysql-connector-java') testCompile('org.springframework.boot:spring-boot-starter-test') // 生成war包 providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')}
2. 修改Application.java文件
- Application.java
@SpringBootApplicationpublic class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); }}
也可以单独写在另一个类中,效果是一样的
- ServletInitializer.java
public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); }}
这样使用
gradle build
进行编译时就可以生成War包了
需要注意的是providedRuntime 仅在打包时才会添加依赖,可能会影响测试
- War 插件添加了两个依赖配置: providedCompile 和 providedRuntime。虽然它们有各自的compile 和 runtime 配置,但这些配置有相同的作用域,只是它们不会添加到 WAR 文件中。要特别注意,这些 provided 配置的传递使用。假设你添加 commons-httpclient:commons-httpclient:3.0 依赖到任何一个 provided 配置。这个依赖又依赖于 commons-codec。这意味着 httpclient 和 commons-codec 都不会添加到你的 WAR 中,即使 commons-codec 是 compile 配置上的一个显示依赖。如果你不想要这种传递行为,只是把 provided 依赖声明成和commons-httpclient:commons-httpclient:3.0@jar 一样。
阅读全文
0 0
- SpringBoot项目生成War包
- SpringBoot项目war包部署tomcat8
- springboot项目以war包形式部署
- IDEA创建基于springboot的多个module聚合项目,并生成war包
- springboot war包部署
- SpringBoot打成war包
- springboot打成war包
- springboot war包导出
- springBoot 打成war包
- 搭建 Springboot maven 项目 并且打war包 发布
- 通过Tomcat配置、启动Springboot项目war包程序
- idea打包SpringBoot项目打包成jar包和war
- springboot项目 打成war包 使用自定义tomcat配置
- springboot打包为war包
- springboot 用war包部署
- 如何生成war包
- 如何生成war包
- MyEclipse生成WAR包
- 文件上传
- mac 安装kafaka
- 路由汇总的计算方法及与CIDR的区别
- iOS-ReactiveObjC 的高级使用(二)
- 练习13
- SpringBoot项目生成War包
- 第十三篇:JAVA之异常处理
- Hibernate4实战之Hibernate4注解零配置 浏览(88173)|评论(0) 交流分类:Java|笔记分类: 未分类 @Entity,注册在类头上,将一个类声明为一个实体bean
- CoreJava day01
- Android 那些你所不知道的Bitmap对象详解
- 简单说 JavaScript中的tostring( ) 与 valueOf( )方法
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
- 官网下载Eclipse地址,可选择版本
- 常见复杂计算发生的复杂度