I am trying to inject properties file into my spring component using CdI and keeps throwing the exception below.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Properties ValidationService.ProjectProperties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.util.Properties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @PropertiesFromFile(value=config.properties)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
Here is my code:
@Component
public class ValidationService {
@Autowired
@PropertiesFromFile("config.properties")
private Properties configProperties;
@Autowired
@PropertiesFromFile("custom.properties")
private Properties customProperties;
}
Another piece of code that I tried was:
@Component
public class ValidationService {
@Inject
@PropertiesFromFile("config.properties")
private Properties configProperties;
@Inject
@PropertiesFromFile("custom.properties")
private Properties customProperties;
}
Although Spring now supports Inject under AutoWired I still tried both.
I am new to Spring, I would really appreciate if someone could point me to the right direction
P.S. The code for the Generic annotation can be found here: http://slackspace.de/articles/injecting-properties-in-java-ee-applications/