spring - 如何在 Spock 测试中将 @Value 注释与 Spring PropertyPlaceholderConfigurer 一起使用?

标签 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 种配置方式。现在我让它们都指向同一个属性文件。

最佳答案

如果您已经设置了 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/

相关文章:

java - Spring Security 初始化在 mvcContentNegotiationManager 上抛出 UnsatisfiedDependencyException

PFGeoPoint 的 Swift 解析查询不显示多个注释

java - Java如何实现注解(元数据)中声明的方法?

dependency-injection - Ninject 多层控制台应用程序

java - GWT 请求工厂 - 如何让定位器工作

java - 由于 spring 注入(inject),Junit 方法调用失败

java - 实现 ApplicationContextAware - ApplicationContext 为 NULL

spring - 由 : java. lang.IllegalArgumentException 引起:无法解析值 'some.other.property' 中的占位符 "${some.other.property}"

java - @InjectMocks 通过构造函数和 setter 注入(inject) @MockBean 无法正常工作

c# - RegisterOpenGeneric with SimpleInjector 解析不正确的类型