maven profile多环境动态配置文件使用
pom.xml
<profiles>
<!-- =====开发环境====== -->
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<!-- 微服务配置 -->
<dubbo.version>server.hbd</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>192.16.8.126</redis.ip>
<redis.port>6379</redis.port>
<redis.pass>cor2017</redis.pass>
<!-- swagger接口 -->
<swagger.enable>true</swagger.enable>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!-- =======UAT环境========== -->
<profile>
<id>uat</id>
<properties>
<env>uat</env>
<!-- 微服务配置 -->
<dubbo.version>server.positec</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>127.0.0.1</redis.ip>
<redis.port>15552</redis.port>
<redis.pass>positec2017...</redis.pass>
<!-- swagger接口 -->
<swagger.enable>true</swagger.enable>
</properties>
</profile>
<!-- ======生产环境====== -->
<profile>
<id>prod</id>
<properties>
<env>prod</env>
<!-- 微服务配置 -->
<dubbo.version>server.positec</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>127.0.0.1</redis.ip>
<redis.port>6379</redis.port>
<redis.pass>123</redis.pass>
<!-- swagger接口 -->
<swagger.enable>false</swagger.enable>
</properties>
</profile>
</profiles>
<build>
<resources>
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<!-- 设置对某些文件进行过滤, 这里对*.properties进行过虑,即这些文件中的${key}会被替换掉为真正的值 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!--<archiveClasses>true</archiveClasses>-->
<warName>${project.artifactId}</warName>
<!--<warSourceDirectory>${basedir}/src/main</warSourceDirectory>-->
<webappDirectory>${project.build.directory}/${project.artifactId}
</webappDirectory>
<webResources>
<resource>
<!-- 由于我是把配置文件都在/WEB-INF/config/文件夹-->
<!-- 所以把src/main/resources 被filter替换的文件替换dao WEB-INF/config/下-->
<directory>src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
spring boot application.properties配置文件
## spring boot 必须用@xx@符号, 不用${}
spring.profiles.active=@env@
#环境dev=开发, prod=生产, uat=用户测试
env=@env@
#IP
redis.ip=@redis.ip@
#Port
redis.port=@redis.port@
redis.pass=@redis.pass@
dubbo.zoo.connectString=@dubbo.zoo.connectString@
dubbo.version=@dubbo.version@
swagger.enable=@swagger.enable@
其他模块普通配置文件
redis.ip=${redis.ip}
#Port
redis.port=${redis.port}
redis.pass=${redis.pass}
spring boot 和普通的方式不同,需要用@@符号占位符,普通方式用${}符号占位
profiles可以被子模块继承,
<build><resources>配置很重要。
maven profile多环境动态配置文件使用的更多相关文章
- maven profile多环境自动切换配置,配置分离,排除文件
痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环境对项目的需求也不相同. 在此之前,我们往往需要手动去修改相对应的配置文件然后打成war,才能部 ...
- maven profile 多环境
<profiles> <profile> <!-- 本地开发环境 --> <id>dev</id> <properties> & ...
- (转载)maven profile多环境自动切换配置
原文:https://www.cnblogs.com/adeng/p/7059588.html 痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环 ...
- maven profile动态选择配置文件
一.背景 在开发过程中,我们的软件会面对不同的运行环境,比如开发环境.测试环境.生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配 ...
- 使用maven profile指定配置文件打包适用多环境
新建maven项目, 在pom.xml中添加 profile节点信息如下: <profiles> <profile> <!-- 开发环境 --> <id& ...
- Spring boot项目分环境Maven打包,动态配置文件,动态配置项目
Spring boot Maven 项目打包 使用Maven 实现多环境 test dev prod 打包 项目的结构 在下图中可用看出,我们打包时各个环境需要分开,采用 application-环境 ...
- 项目实现不同环境不同配置文件-maven profile
最近接触的项目都是在很多地方都落地的项目,需要支持不同的环境使用不同的配置文件.一直以来都以为是人工的去写不同的配置文件,手动的去修改运用的配置文件.感觉自己还是太low呀.maven的使用的还停留在 ...
- 【转】maven profile实现多环境打包
作为一名程序员,在开发的过程中,经常需要面对不同的运行环境(开发环境.测试环境.生产环境.内网环境.外网环境等等),在不同的环境中,相关的配置一般不一样,比如数据源配置.日志文件配置.以及一些软件运行 ...
- Maven根据不同环境打包不同配置文件
开发项目时会遇到这个问题:开发环境,测试环境,生产环境的配置文件不同,打包时经常要手动更改配置文件,更改的少还可以接受,但是如果需要更多个配置文件,手动的方法就显得非常笨重了. 下面介绍一种方法,利用 ...
随机推荐
- PHP垃圾回收机制引用计数器概念
参考: http://www.phpddt.com/php/gc-refcounting-basics.html
- mybatis的#和$的差别
在项目中假设使用mybatis保存形如"1,2,3"这种字符串.你须要使用"#"号取值.假设使用$符号会报错, 假设是查询形如"id in (1,2, ...
- Android Studio 使用感受 错误解决
刚到公司不久,公司叫我用Android studio软件,曾经一直在用的是eclipse ADT.突然接触到的新名词让我有点适应只是来. 好吧,既然是公司要求,肯定有它的道理.就从网上下载了它的安装包 ...
- Cadence技巧01:利用Excel速新建原理图元件库
Cadence技巧01:利用Excel速新建原理图元件库 听语音 | 浏览:1698 | 更新:2015-07-02 09:41 | 标签:excel 1 2 3 4 5 6 7 分步阅读 一键约师傅 ...
- libvirt网络过滤规则简单总结
libvirt网络过滤规则, 一个过滤规则定义的示例: < filter name='no-ip-spoold'chain='ipv4' > < uuid >fce8ae33 ...
- Struts2使用OGNL遍历各种map总结
一.Action中的代码:MapAction.java package com.zx.demo.action; import java.util.ArrayList; import java.ut ...
- 18. Subsets II【medium】
Given a list of numbers that may has duplicate numbers, return all possible subsets Notice Each elem ...
- 教程-Delphi中的GExperts搜索代码快捷键
Shift+Ait+S 打开搜索 Ctrl+Ait+R 打开上次搜索结果
- 纯css3实现的win8加载动画
今天给大家分享一款纯css3实现的win8加载动画.在这款实例中动画效果完全由css3实现.一起看下效果图: 在线预览 源码下载 实现的代码. html代码: <div class=&quo ...
- boa 服务的启动
使用 buildroot 添加 boa 服务后,通过命令 boa 不能启动该服务,就研究了一下boa.conf的配置. etc/boa/boa.conf # 更改user 和Group 为root. ...