【发布时间】:2012-11-23 13:26:48
【问题描述】:
我有以下配置类:
@Configuration
@PropertySource(name = "props", value = "classpath:/app-config.properties")
@ComponentScan("service")
public class AppConfig {
我有物业服务:
@Component
public class SomeService {
@Value("#{props['some.property']}") private String someProperty;
当我想测试 AppConfig 配置类时收到错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String service.SomeService.someProperty; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'props' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
问题记录在in SPR-8539
但无论如何我不知道如何配置 PropertySourcesPlaceholderConfigurer 以使其正常工作。
编辑 1
这种方法适用于 xml 配置
<util:properties id="props" location="classpath:/app-config.properties" />
但我想使用java进行配置。
【问题讨论】:
-
你能接受laffuste的回答吗?它有效。
-
完成 :) 我没有进行更多调查,但提到勾选标记为“不会修复”
标签: spring configuration