在application.properties后缀的配置文件中我们如下使用MAVEN变量:
eureka.client.serviceUrl.defaultZone=@defaultZone@
@运行时符号会自替换成MAVEN变量配置好的值,但是换成YML配置文件不行了,会报错,如下配置即可解决:
eureka:
client:
service-url:
defaultZone: '@defaultZone@'
maven pom.xml配置
<profiles>
<profile>
<id>测试配置</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>${java.version}</jdk>
</activation>
<properties>
<!-- mysql database url -->
<driverClassName>com.mysql.jdbc.Driver </driverClassName>
<url>jdbc:mysql://localhost:3306/db</url>
<username>root</username>
<password></password>
<defaultZone>http://localhost:8500/eureka/</defaultZone>
countURL>
</properties>
</profile>
<profile>
<id>仿真配置</id>
<properties>
<!-- mysql database url -->
<driverClassName>com.mysql.jdbc.Driver </driverClassName>
<url>jdbc:mysql://localhost:3306/db</url>
<username>root</username>
<password></password>
<defaultZone>http://localhost:8500/eureka/</defaultZone>
ccountURL>
</properties>
</profile>
<profile>
<id>生产配置</id>
<properties>
<!-- mysql database url -->
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/db</url>
<username>root</username>
<password></password>
<defaultZone>http://localhost:8500/eureka/</defaultZone>
</properties>
</profile>
</profiles>
本文介绍了在使用application.yml配置文件时如何正确处理MAVEN变量替换,尤其是在Eureka客户端的service-url.defaultZone配置中。对比了application.properties中的自动替换机制,并给出了mavenpom.xml中不同环境配置示例。

1405

被折叠的 条评论
为什么被折叠?



