Muh*_*riq 6 java spring dependency-injection spring-mvc autowired
我收到了这个错误
org.springframework.beans.factory.BeanCreationException:
Could not autowire method:
Run Code Online (Sandbox Code Playgroud)
这是我的spring的xml配置.
<bean ...>
...
<property name="InfoModel" ref="InfoModel"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我在Java类中自动装配它
private InfoModel infoModel;
@Autowired
public void setInfoModel(InfoModel infoModel) {
this.infoModel= infoModel;
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么.我怀疑,我应该作出Interface的InfoModel以使其自动装配?
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)
Run Code Online (Sandbox Code Playgroud)
Jig*_*shi 12
如果你这样做,@Autowired你不需要在xml中将其标记为属性.只需将InfoModel声明为XML格式的bean,然后property从xml中删除已注入的beanInfoModel
加起来
1您需要在XML中使用bean定义InfoModel
2您需要property从XML中删除
3确保通过添加驱动了上下文注释
<context:annotation-config />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13374 次 |
| 最近记录: |