注入的原始奇怪的例外,我对试图通过注入春天@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