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 ...
随机推荐
- Linux 系统的/usr目录
/usr不是user的缩写,其实usr是Unix Software Resource的缩写, 也就是Unix操作系统软件资源所放置的目录,而不是用户的数据:所有系统默认的软件都会放置到/usr, 系统 ...
- Linux系统优化实现高并发
ulimit -SHn 65535内核优化net.ipv4.ip_forward = 1 #开启路由功能net.ipv4.conf.default.rp_filter = 1 ...
- Hybris阶段总结(1)何为hybris
按照谷歌出来的结果,大体意思是“Hybris Commerce是一套完善的电子商务解决方案,基于开放标准构建,功能强大,且具有模块化的特点,旨在为满足企业的商务需求提供坚实的基础”. 当然对于我这样 ...
- 多数据源报错 expected single matching bean but found 2: xxx,xxx
问题: expected single matching bean but found 2: xxx,xxx 原因:在 Spring 容器中配置了两个类型Bean,Spring 容器将无法确定到底要用 ...
- 面对对象程序设计_task2_1001.A+B Format (20)
Someting about 1001.A+B Format (20) 问题描述及我所写的代码:click here → My Task 看到这个题目的时候,我的想法很简单,直接判断直接输出,因为给定 ...
- Gsoap在QT工程里如何调用
Qt并没有SOAP的官方实现,都是借助三方库来实现,不过似乎有个QtSoap,不过这个不是太会用,所以还是用Gsoap 这里生成纯C文件, 1.下载gSOAP(http://sourceforge.n ...
- [咸恩静][Good Bye]
歌词来源:http://music.163.com/#/song?id=35437298 作曲 : 安英民 [作曲 : 安英民] 作词 : 安英民/로코 [作词 : 安英民/lo-Ko] 나를 떠나버 ...
- 学习HTTP
http://blog.csdn.net/lmh12506/article/details/7794512 HTTP协议是无状态的和Connection: keep-alive的区别 http协议是无 ...
- 切换composer国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
- P4906 小奔关闹钟
题目背景 由于今天是星期一,闹钟准时响了,由于小奔太困了,所以她想关停闹钟. 题目描述 可是,他的闹钟电路太复杂了,有很多个开关,每个开关都连着其他开关,其他开关又连着更多的开关,当且仅当所有开关都关 ...