我收到这个错误
org.springframework.beans.factory.BeanCreationException:
Could not autowire method:
这是我的spring的xml配置。
<bean ...>
...
<property name="InfoModel" ref="InfoModel"></property>
</bean>
这是我的代码,我在 Java 类中自动装配它
private InfoModel infoModel;
@Autowired
public void setInfoModel(InfoModel infoModel) {
this.infoModel= infoModel;
}
我是不是错过了什么。我怀疑我应该做一个Interface
of 信息模型为了使其自动装配?
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)
如果你这样做@Autowired
您不需要将其标记为 xml 中的属性。只需将 InfoModel 声明为 XML 中的 bean 并删除property
来自您注入的 bean 的 xmlInfoModel
加起来
1您需要在 XML 中定义 beanInfoModel
2你需要删除property
来自 XML
3确保您已通过添加驱动上下文注释
<context:annotation-config />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)