Wartość @Value nie została rozwiązana podczas używania adnotacji @PropertySource. Jak skonfigurować PropertySourcesPlaceholderConfigurer?
Mam następującą klasę konfiguracji:
@Configuration
@PropertySource(name = "props", value = "classpath:/app-config.properties")
@ComponentScan("service")
public class AppConfig {
i mam usługę z nieruchomością:
@Component
public class SomeService {
@Value("#{props['some.property']}") private String someProperty;
Otrzymuję błąd, gdy chcę przetestować klasę konfiguracji AppConfig za pomocą
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'
Problem jest udokumentowanyw SPR-8539
ale w każdym razie nie mogę dowiedzieć się, jak skonfigurowaćPropertySourcesPlaceholderConfigurer aby to zadziałało.
Edytuj 1Podejście to działa dobrze w konfiguracji xml
<util:properties id="props" location="classpath:/app-config.properties" />
ale chcę użyć Java do konfiguracji.