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多环境动态配置文件使用的更多相关文章

  1. maven profile多环境自动切换配置,配置分离,排除文件

    痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环境对项目的需求也不相同. 在此之前,我们往往需要手动去修改相对应的配置文件然后打成war,才能部 ...

  2. maven profile 多环境

    <profiles> <profile> <!-- 本地开发环境 --> <id>dev</id> <properties> & ...

  3. (转载)maven profile多环境自动切换配置

    原文:https://www.cnblogs.com/adeng/p/7059588.html 痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环 ...

  4. maven profile动态选择配置文件

    一.背景 在开发过程中,我们的软件会面对不同的运行环境,比如开发环境.测试环境.生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配 ...

  5. 使用maven profile指定配置文件打包适用多环境

    新建maven项目,   在pom.xml中添加 profile节点信息如下: <profiles> <profile> <!-- 开发环境 --> <id& ...

  6. Spring boot项目分环境Maven打包,动态配置文件,动态配置项目

    Spring boot Maven 项目打包 使用Maven 实现多环境 test dev prod 打包 项目的结构 在下图中可用看出,我们打包时各个环境需要分开,采用 application-环境 ...

  7. 项目实现不同环境不同配置文件-maven profile

    最近接触的项目都是在很多地方都落地的项目,需要支持不同的环境使用不同的配置文件.一直以来都以为是人工的去写不同的配置文件,手动的去修改运用的配置文件.感觉自己还是太low呀.maven的使用的还停留在 ...

  8. 【转】maven profile实现多环境打包

    作为一名程序员,在开发的过程中,经常需要面对不同的运行环境(开发环境.测试环境.生产环境.内网环境.外网环境等等),在不同的环境中,相关的配置一般不一样,比如数据源配置.日志文件配置.以及一些软件运行 ...

  9. Maven根据不同环境打包不同配置文件

    开发项目时会遇到这个问题:开发环境,测试环境,生产环境的配置文件不同,打包时经常要手动更改配置文件,更改的少还可以接受,但是如果需要更多个配置文件,手动的方法就显得非常笨重了. 下面介绍一种方法,利用 ...

随机推荐

  1. mysql group replication 安装&配置详解

    一.原起: 之前也有写过mysql-group-replication (mgr) 相关的文章.那时也没有什么特别的动力要写好它.主要是因为在 mysql-5.7.20 之前的版本的mgr都有着各种各 ...

  2. Android_WebServices_源代码分析

    本博文为子墨原创,转载请注明出处! http://blog.csdn.net/zimo2013/article/details/38037989 在Android_WebServices_介绍一文中, ...

  3. vim -d file01 file02 diff file01 file02 对比两文件的不同

    [root@86 vhosts]# vim -d defaul.conf.bak zabbix.xinxianm.com.conf server { | server { listen 80; | l ...

  4. FreeRtos——多任务

    官方资料整理测试: 多任务和单任务几乎没有差别.只用多创建一个或多个任务,其他地方和单任务时相同. static void AppTaskCreate(void) { xTaskCreate(vTas ...

  5. [C++]using std string;的作用是什么

    相关资料: http://bbs.csdn.net/topics/330194465 #include <string>将string库包含到当前编译单元中. using std::str ...

  6. Java反射机制在代理模式中的使用

    代理模式的核心思路就是一个接口有两个子类,一个子类完成核心的业务操作,另一个子类完成与核心业务有关的辅助性操作. 代理模式分为静态代理模式和动态代理模式.  静态代理模式: //接口类 interfa ...

  7. QT在CT上的安装及运行

    http://www.cubie.cc/forum.php?mod=viewthread&tid=2662&highlight=qt

  8. Ajax的两个用法

    1.实现的效果是:通过一个函数,里面调用Ajax,函数的返回值是Ajax成功调用之后得到的返回值. 用jQuery进行简单的演示: function getRobotInfo(id) { var ip ...

  9. 浅谈Facebook的服务器架构(组图)

    导读:毫无疑问,作为全球最领先的社交网络,Facebook的高性能集群系统承担了海量数据的处理,它的服务器架构一直为业界众人所关注.CSDN博主yanghehong在他自己最新的一篇博客< Fa ...

  10. C语言 百炼成钢24

    /* 题目60:从键盘中输入一个不超过40个字符的字符串, 再输入3个位数(每次删除一个字符),删除对应 位数的字符,然后输出删除指定字符后的字符串. 输入:hellokityManGood 3 6 ...