2015-04-16 65 views
0

注入的原始奇怪的例外,我对试图通过注入春天@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]并不能找到一个。

+0

哪个版本的Spring? 3.0.5有可能会导致此错误:https://jira.spring.io/browse/SPR-8574 – sheltem

+0

你有一个'PropertySourcePropertyPlaceholderConfigurer'配置? –

+0

是的,它是配置,但其结果同样 – dim1902

回答

0

变化@PropertySource("classpath:applicationConfig.properties")@PropertySource("classpath:myProps.properties")或使用@PropertySources注解。

+0

谢谢你的评论,我的错误 - 在这两种情况下使用myProps.properties。不幸的是,它不是bug的来源 – dim1902