一般的我们的应用程序会有多个参数环境,例如本地开发环境,测试环境,准生产环境,生产环境等等。每重新发布到一个新环境就改一堆参数是不是很繁琐?maven提供一个便捷的方式,多环境配置。具体如下。
首先在pom文件中增加profile,
pom.xml
local nbsp;local true beta beta pre pre product product src/main/resources/config/profile-${env}.properties src/main/resources true
文件目录结构:
src/main/resources/config.properties
src/main/resources/config/profile-local.properties
src/main/resources/config/profile-beta.properties
src/main/resources/config/profile-pre.properties
src/main/resources/config/profile-product.properties
具体文件内容:
config.properties
#———–
redisIP=${redisIP}
tokenKey=${tokenKey}
profile-local.properties
#————
redisIP=localhost
tokenKey=ac_ak947
logDir=d:/logs
其他profile文件和profile-local相似。
编译方法:
eclipse下 maven build…->
goals填写 clean jetty:run
profile填写 local
则用profile-local.properties编译
填写beat则用profile-beta.properties
编译内容会替换config.properties中的${…}