I am getting this error
org.springframework.beans.factory.BeanCreationException:
Could not autowire method:
This is my spring's xml configuration.
<bean ...>
...
<property name="InfoModel" ref="InfoModel"></property>
</bean>
Here is my code where I am autowiring this in Java class
private InfoModel infoModel;
@Autowired
public void setInfoModel(InfoModel infoModel) {
this.infoModel= infoModel;
}
Am I missing something. I suspect that I should make an Interface
of InfoModel in order to make it autowire?
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.model.InfoModel] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:547)
if you do @Autowired
you don't need to mark it as property in xml. just declare InfoModel as bean in XML and remove property
from xml for you bean where you have injected InfoModel
Summing up
1 You need a bean definition in your XML for InfoModel
2 You need to remove property
from XML
3 Make sure you have made your context annotation driven by adding
<context:annotation-config />
If the stack trace says there are no matching beans of said type, then that's what wrong.
Add the InfoModel bean to the spring application context, e.g. by declaring the bean in the same xml configuration:
<bean id="InfoModel" class="com.model.InfoModel" />
btw. you shouldn't capitalize the first letter of the bean identifier, follow the same naming convention as for variables, ie. lowerCamelCase. Autowiring and explicitly injecting the dependency is also redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With