У меня есть следующий класс конфигурации:
@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'
Проблема документирована в SPR-8539
но в любом случае я не могу понять, как настроить PropertySourcesPlaceholderConfigurer, чтобы он работал.
Изменить 1
Этот подход хорошо работает с конфигурацией xml
<util:properties id="props" location="classpath:/app-config.properties" />
но я хочу использовать java для конфигурации.