springboot之assembly的文件配置
一、在使用springboot框架的时候,存在一个问题。就是我们配置yaml文件,需要单独提出来做参数修改。当然这个是可以通过spring.profiles.active的方式来配置dev,prod等环境的激活。但是我们如果存在环境不确定,或者需要启动脚本,启动项目的时候,这样通过jar的方式后续会处理很多工作。所以前期的集成工作还是很有必要的。
二、这里有一个简单的例子,用于参数配置方式
1)目录结构

2)需要的依赖包(pom.xml)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3)maven的构建过程
<build>
<finalName>assembly</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<!--主要使用的是maven提供的assembly插件完成-->
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<!--具体的配置文件-->
<descriptors>${project.basedir}/src/main/resources/assembly/package.xml</descriptors>
</configuration>
<id>make-assembly</id>
<!--绑定到maven操作类型上-->
<phase>package</phase>
<!--运行一次-->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
4)集成过程(package.xml)
<?xml version='1.0' encoding='UTF-8'?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<!--打包名称,唯一标识-->
<id>${project.build.finalName}</id>
<!--打包格式,可以手动修改-->
<formats>
<format>tar.gz</format>
</formats>
<!--文件设置-->
<fileSets>
<fileSet>
<!--目标目录,会处理目录里面的所有文件-->
<directory>${project.basedir}/src/main/resources/config</directory>
<!--相对于打包后的目录-->
<outputDirectory>config</outputDirectory>
<!--文件过滤-->
<includes>
<include>*.*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources/script</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.*</include>
</includes>
<!--文件权限-->
<fileMode>0755</fileMode>
<!--如果是脚本,一定要改为unix.如果是在windows上面编码,会出现dos编写问题-->
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets>
<files>
<!--包含打包后的jar文件,可以不加入<outputDirectory/>,默认打包的目录-->
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
</file>
<!--这种方式也可以进行文件处理,但是针对单文件-->
<!-- <file>
<source>${project.basedir}/src/main/resources/script/start.sh</source>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</file>-->
</files>
</assembly>
备注:具体的参数的意义可以参考官网:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
5)通过maven的package打包



三、源码:https://github.com/lilin409546297/springboot-assembly
springboot之assembly的文件配置的更多相关文章
- SpringBoot入门-多环境文件配置(二)
pom.xml <name>springboot-application</name> <description>A project for Spring Boot ...
- SpringBoot中自定义properties文件配置参数并带有输入提示
1. 创建配置类 在项目中创建一个参数映射类如下 @ConfigurationProperties(prefix = "user.info") public class MyPro ...
- 【2.0】SpringBoot多环境yml文件配置
一.使用Spring Boot Profiles 1. 使用yml文件 首先,我们先创建一个名为 application.yml的属性文件,如下: server: port: 8080 my: nam ...
- Spring-Boot注入自定义properties文件配置
创建wzq.properties wzq.properties注入User实体类中 @PropertySource(value = "classpath:wzq.properties&quo ...
- SpringBoot 项目打包分开lib,配置和资源文件
原文地址:https://blog.csdn.net/u012811805/article/details/80878848 1 jar启动分离依赖lib和配置 先前发布boot项目的时候,改动一点东 ...
- ******可用 SpringBoot 项目打包分开lib,配置和资源文件
spring-boot多模块打包后,无法找到其他模块中的类https://blog.csdn.net/Can96/article/details/96172172 关于SpringBoot项目打包没有 ...
- 在springboot pom文件配置过程,`spring-boot-maven-plugin`配置出错的问题解决及配置过程出现问题的一些思考
在springboot pom文件配置过程,spring-boot-maven-plugin配置出错的问题解决及配置过程出现问题的一些思考 解决方法一: 也是最简单的方法,可能是maven没有来得及导 ...
- SpringBoot多重属性文件配置方案笔记
SpringBoot多重属性文件配置方案笔记 需要重写PropertyPlaceholderConfigurer 同时要忽略DataSourceAutoConfiguration @SpringBoo ...
- Springboot多属性文件配置
Springboot 多属性文件配置 配置文件后缀有两种: .properties和.yml 要完成多属性配置需要自定义PropertySourcesPlaceholderConfigurer 这个B ...
随机推荐
- ActiveMq--消息队列
ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ的目录: bin存放的是脚本文件 conf存放的是基本配置文件 data ...
- 官方推荐的MySQL参数设置值
这oracle官方推荐的在OLTP环境下,MySQL参数设置的最佳实践. 下面的参数设置,对系统的性能会很有帮助.但是建议大家还是结合实际情况使用. APPLIES TO: MySQL Server ...
- umount nfs文件系统 显示 umount.nfs: device is busy
网上的方法一般都是 fuser -m /nfs 查出进程号,然后杀死进程号,或者fuser -km /nfs直接杀死,我试了下都不行 解决方法: 对于nfs文件系统来说,umount -l /nfs ...
- Virtual PC局域网共享速度慢的解决半法。转
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DisableTaskOffload 新建字符串,名:DisableTaskOffloa ...
- 通过Python实现一个文档的半自动录入工具
需求出现/使用场景: 因为公司需要将word办的接口文档在线化,看起来是个很好的事情,但是就是苦逼了我们这些干活的,其中工程量最大的就是参数的录入,要是参数少也罢,有的接口动辄三四十个参数,更甚八九十 ...
- Python的multiprocessing,Queue,Process
在多线程multiprocessing模块中,有两个类,Queue(队列)和Process(进程): 在Queue.py中也有一个Queue类,这两个Queue的区别? from multiproce ...
- Spring-IOC bean 创建过程中的 ObjectFactory
AbstractBeanFactory中doGetBean方法里有一段拿到RootBeanDefinition后,实例化该bean的方法 // Create bean instance. if (mb ...
- Spring Boot Mock单元测试学习总结
单元测试的方法有很多种,比如使用Postman.SoapUI等工具测试,当然,这里的测试,主要使用的是基于RESTful风格的SpringMVC的测试,我们可以测试完整的Spring MVC流程,即从 ...
- 20145203盖泽双 《Java程序设计》第6周学习总结
20145203盖泽双 <Java程序设计>第6周学习总结 教材学习内容总结 1.如果要将数据从来源中取出,可以使用输入串流,若将数据写入目地, 可以使用输出串流.在java中,输入串流代 ...
- c++ 堆和栈以及区别
c++中内存分成5个区:堆.栈.自由存储区.全局\静态存储区.常量存储区 栈是一种连续存储的数据结构,具有先进后出的性质.堆是一种非连续的树形存储数据结构,每个节点有一个值,整棵树是经过排序的,特点是 ...