注入的原始奇怪的例外,我對試圖通過注入春天@Value註解(Spring版本3.2.13)INT原始奇怪的錯誤。簡短描述:Spring試圖注入原始類型(int在我的情況下)而不是原始本身的bean。上通過Spring @Value註解
我有屬性文件 「myProps.properties」 財產掃描路徑上
number.of.search.log.events.in.queue=4
配置類內容
@Configuration @ComponentScan(basePackages = { "com.search.log" }) @PropertySource("classpath:myProps.properties") @EnableAspectJAutoProxy public class SearchLogConfiguration { @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } }
方面的基礎原始應注射
@Aspect @Component public class SearchLogAspectHandler { @Value("${number.of.search.log.events.in.queue:2}") public int numberOfSearchLogEventsInQueue; ... }
每次在應用程序啓動,我得到這個異常:
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public int numberOfSearchLogEventsInQueue; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [int] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Value(value=${number.of.search.log.events.in.queue})}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:298)
元也不能注入到其他豆類爲好。
問:請幫助找出爲什麼春天不能注入原始的,而是試圖注入類型的豆[INT]並不能找到一個。
哪個版本的Spring? 3.0.5有可能會導致此錯誤:https://jira.spring.io/browse/SPR-8574 – sheltem
你有一個'PropertySourcePropertyPlaceholderConfigurer'配置? –
是的,它是配置,但其結果同樣 – dim1902