我引用了 Spring 的 @Value
注释,如下所示:@Value和 Spring 配置文件。
我需要能够为给定属性设置不同的值,例如:
websiteContext=http://localhost:8080/kadjoukor
...根据应用程序是在本地运行还是在云端运行。我不确定如何使用 @Value("${websiteContext}")
注释来实现这一点...
处理此类问题的最佳做法是什么?
最佳答案
如果您使用 Spring 3.1 或更高版本,则可以利用 bean 配置文件和 CloudFoundry“云”配置文件根据环境加载不同的属性文件。在 Spring XML 配置文件中,这可能看起来像这样:
<beans profile="default">
<context:property-placeholder location="default.properties"/>
</beans>
<beans profile="cloud">
<context:property-placeholder location="cloud.properties"/>
</beans>
这里有一些很好的博客文章,更详细地解释了它的工作原理:
关于spring - 在cloudfoundry和@Value注释中处理属性的两个不同值(云和默认值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13913026/