maven profile多环境动态配置文件使用
2017-05-30 18:19
351 查看
pom.xml
spring boot application.properties配置文件
其他模块普通配置文件
spring boot 和普通的方式不同,需要用@@符号占位符,普通方式用${}符号占位
profiles可以被子模块继承,
<build><resources>配置很重要。
<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的resources、filter和profile实现不同环境使用不同配置文件
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件(POM中)
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件
- 利用maven的resources、filter和profile实现不同环境使用不同配置文件
- Maven 进行多环境配置,使用profile文件进行配置
- maven: 开发、测试和生产环境使用不同的配置文件例子
- [置顶] spring mvc 利用maven实现不同环境使用不同配置文件
- 使用 MAVEN 进行不同环境的服务配置文件管理
- 使用MAVEN动态生成配置文件
- Maven_profile_使用profile配置不同环境的properties(实践)
- Maven根据Profile读取不同配置环境配置文件
- maven profile 结合spirng注解使用——实现配置文件最小化
- Maven根据Profile读取不同配置环境配置文件
- Maven使用profile 和 filtering实现多种环境下配置打包
- 使用Maven自动打包配置文件生成开发环境,测试环境,生产环境
- maven下多环境配置文件、属性管理 & Spring使用@value初始化字段值
- Spring Boot使用profile如何配置不同环境的配置文件