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根据不同环境打包不同配置文件
开发项目时会遇到这个问题:开发环境,测试环境,生产环境的配置文件不同,打包时经常要手动更改配置文件,更改的少还可以接受,但是如果需要更多个配置文件,手动的方法就显得非常笨重了. 下面介绍一种方法,利用 ...
随机推荐
- LDA与QDA
作者:桂. 时间:2017-05-23 06:37:31 链接:http://www.cnblogs.com/xingshansi/p/6892317.html 前言 仍然是python库函数sci ...
- Nginx配置优化详解
如果你已经安装过Nginx并在生产环境中使用,那么Nginx配置优化你一定也要做,这样才能看到Nginx性能,本文就从基本配置优化开始到高层配置教你如何优化Nginx 大多数的Nginx安装指南告诉你 ...
- Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 33554432 bytes
MongoDB执行错误: Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 335 ...
- struts2防止表单重复提交的解决方案
一.造成重复提交主要的两个原因: 在平时的开发过程中,经常可以遇到表单重复提交的问题,如做一个注册页面,如果表单重复提交,那么一个用户就会注册多次,重复提交主要由于两种原因. 1. 一是,服务器 ...
- python-爬图小样
python-爬某页面图 注意:python3+版本与python2有一定区别,需要注意多点. #! /usr/bin/env python3.5.4 # coding=utf-8 # 爬百度某贴吧页 ...
- vue知识点2018.6.3
文件夹和文件名称 简介 build 构建脚本目录 config 应用程序的配置文件 index.html 入口页面 node_modules 存放 NPM 依赖模块 package-lock.json ...
- filebeat+kafka失败
filebeat端配置 #----------------------------- Kafka output -------------------------------- output.kafk ...
- FMC—扩展外部 SDRAM
本章参考资料:< STM32F4xx 参考手册 2>.< STM32F4xx 规格书>.库帮助文档< stm32f4xx_dsp_stdperiph_lib_um.chm ...
- 基于html5和css3响应式全屏滚动页面切换效果
分享一款全屏响应式的HTML5和CSS3页面切换效果.这个页面布局效果对于那些页面要求固定100%高度和宽度的网站和APP来说是十分有用的.效果图如下: 在线预览 源码下载 HTML wrappe ...
- 原创jQuery插件之图片自适应
效果图例如以下: 功能:使图片自适应居中位于容器内 限制:容器须要给定大小 用法: 1.引入jQuery.然后引入fitimg插件 2.给须要图片自适应的容器固定宽高 3.header .accoun ...