I have strange error on attempt to inject int primitive via Spring @Value annotation (Spring version 3.2.13). Short description: Spring is trying to inject bean of primitive type (int in my case) instead of primitive itself.
I have property file "myProps.properties" with property
number.of.search.log.events.in.queue=4
Configuration class on scanned path with content
@Configuration @ComponentScan(basePackages = { "com.search.log" }) @PropertySource("classpath:myProps.properties") @EnableAspectJAutoProxy public class SearchLogConfiguration { @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } }
Aspect where primitive should be injected
@Aspect @Component public class SearchLogAspectHandler { @Value("${number.of.search.log.events.in.queue:2}") public int numberOfSearchLogEventsInQueue; ... }
Every time on application start I got this exception:
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)
Also primitives can't be injected into other beans as well.
Question: Please, help to find out why Spring can't inject primitive, but instead is trying to inject bean of type [int] and can't found one.