可以将 @Value 注释与 Spring PropertyPlaceholderConfigurer 一起使用吗?
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="classpath:application-test.properties" />
<util:properties id="appProperties" location="classpath:application-test.properties" />
使用 @Value 可以正常工作,但我想使用 1 种配置方式。现在我让它们都指向同一个属性文件。
最佳答案
如果您已经设置了 util:properties,则无需使用 PropertyPlaceholderConfigurer。在您的 bean 配置中,创建 util:properties bean,然后在您的类中进行注释,如
@Value("#{myProps.someProperty}")
http://forum.springsource.org/showthread.php?69602-Value-and-PropertyPlaceholderConfigurer
关于spring - 如何在 Spock 测试中将 @Value 注释与 Spring PropertyPlaceholderConfigurer 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569990/