如何在Spock测试中使用Spring PropertyPlaceholderConfigurer使用@Value注释?

时间:2011-07-04 10:05:51

标签: spring dependency-injection annotations spock

可以将@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种配置方式。现在我让他们两个都指向同一个属性文件。

1 个答案:

答案 0 :(得分:3)

如果您已经设置了util:properties,则无需使用PropertyPlaceholderConfigurer。在bean配置中,创建util:properties bean,然后在类中注释,如

@Value("#{myProps.someProperty}")

http://forum.springsource.org/showthread.php?69602-Value-and-PropertyPlaceholderConfigurer

相关问题