Spring 在cloudfoundry和@Value注释中处理属性的两个不同值(cloud和default)
我参考的是Spring的Spring 在cloudfoundry和@Value注释中处理属性的两个不同值(cloud和default),spring,cloud-foundry,properties-file,Spring,Cloud Foundry,Properties File,我参考的是Spring的@Value注释,如本文所述:和Spring概要文件 我需要能够为给定的属性设置不同的值,例如: websiteContext=http://localhost:8080/kadjoukor …根据应用程序是在本地运行还是在云上运行。我不知道如何使用@Value(“${websiteContext}”)注释实现这一点 处理此类问题的最佳实践是什么?如果您使用的是Spring 3.1或更高版本,您可以利用bean配置文件和CloudFoundry“cloud”配置文件根据
@Value
注释,如本文所述:和Spring概要文件
我需要能够为给定的属性设置不同的值,例如:
websiteContext=http://localhost:8080/kadjoukor
…根据应用程序是在本地运行还是在云上运行。我不知道如何使用@Value(“${websiteContext}”)
注释实现这一点
处理此类问题的最佳实践是什么?如果您使用的是Spring 3.1或更高版本,您可以利用bean配置文件和CloudFoundry“cloud”配置文件根据环境加载不同的属性文件。在Spring XML配置文件中可能看起来像这样:
<beans profile="default">
<context:property-placeholder location="default.properties"/>
</beans>
<beans profile="cloud">
<context:property-placeholder location="cloud.properties"/>
</beans>
以下是一些很好的博客文章,详细解释了这一点: