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. 禁止用户登陆的 /bin/false和/sbin/nologin的区别

    1 区别 /bin/false是最严格的禁止login选项,一切服务都不能用. /sbin/nologin只是不允许login系统  小技巧: 查看 /etc/passwd文件,能看到各用户使用的sh ...

  2. id ,NSObject, id<NSObject>区别

    转自:http://blog.csdn.net/happytengfei/article/details/11473931 我们经常会混淆以下三种申明(我是没有留意过):    1. id foo1; ...

  3. [POJ 1236][IOI 1996]Network of Schools

    Description A number of schools are connected to a computer network. Agreements have been developed ...

  4. U盘 格式化 ext3 ext4

    [root@ok Desktop]# mkfs.ext3 /dev/sdc mke2fs 1.41.12 (17-May-2010) /dev/sdc is entire device, not ju ...

  5. html中iframe子页面与父页面元素的访问以及js变量的访问

    1.子页面访问父页面元素   parent.document.getElementById('id')和document相关的方法都可以这样用   2.父页面访问子页面元素   document.ge ...

  6. Linux下C语言编程中库的使用

    零.问题 1. 为什么要用到库? 2. 我要用一个库,但是,尼玛命令行上该怎么写呢?或者说库文件如何使用? 3. Linux的库在那些地方? 4. 什么是静态库,什么是动态库,二者有啥区别? 5. 常 ...

  7. Okra框架(三) 搭建HTTP服务器

    Okra通过封装成熟高效的框架以简化应用程序服务器构建的过程.上一篇介绍了使用Okra快速搭建Socket服务器. 本篇承接上一篇,介绍快速搭建简单高性能的Http服务器. 这里需要说明一下Okra框 ...

  8. per-cpu

    What is percpu data? percpu data 是内核为smp系统中不同CPU之间的数据保护方式,系统为每个CPU维护一段私有的空间,在这段空间中的数据只有这个CPU能访问.但是这种 ...

  9. Bitmap转灰度字节数组byte[]

    工作中遇到图片转灰度数组的须要,经过研究和大神的指导.终于得到例如以下两个方法.能够实现位图转灰度数组 简单的位图转灰度数组就是:得到位图中的每一个像素点,然后依据像素点得到RGB值,最后对RGB值, ...

  10. Entity Framework中的实体类添加复合主键

    使用Code First模式实现给实体类添加复合主键,代码如下: using System; using System.Collections.Generic; using System.Compon ...