【问题标题】:How to use the @Value annotation with a Spring PropertyPlaceholderConfigurer in a Spock test?如何在 Spock 测试中将 @Value 注释与 Spring PropertyPlaceholderConfigurer 一起使用?
【发布时间】:2011-07-04 10:05:50
【问题描述】:

可以将@Value 注解与 Spring PropertyPlaceholderConfigurer 一起使用吗?

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="classpath:application-test.properties"
/>

&lt;util:properties id="appProperties" location="classpath:application-test.properties" /&gt; 可与 @Value 正确配合,但我想使用 1 种配置方式。现在我让它们都指向同一个属性文件。

【问题讨论】:

标签: spring dependency-injection annotations spock


【解决方案1】:

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

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

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

【讨论】:

  • 但是可以只使用PropertyPlaceHolderConfigurer吗?我需要它来替换我的 applicationContext.xml 中的东西,所以我需要 PropertyPlaceHolderConfigurer。
猜你喜欢
  • 1970-01-01
  • 2012-04-06
  • 1970-01-01
  • 1970-01-01
  • 2013-11-06
  • 1970-01-01
  • 2016-01-25
  • 2018-03-03
  • 2012-03-23
相关资源
最近更新 更多