java – 无法自动装配方法

前端之家收集整理的这篇文章主要介绍了java – 无法自动装配方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我收到了这个错误

org.springframework.beans.factory.BeanCreationException: 
Could not autowire method:

这是我的spring的xml配置.

这是我的代码,我在Java类中自动装配

  private InfoModel infoModel;

  @Autowired
  public void setInfoModel(InfoModel infoModel) {
    this.infoModel= infoModel;
  }

我错过了什么.我怀疑我应该创建一个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)
最佳答案
如果您执行@Autowired,则无需在xml中将其标记属性.只需将InfoModel声明为XML格式的bean,并从已注入InfoModel的bean中删除xml中的属性

加起来

1您需要在XML中为InfoModel定义bean

2您需要从XML中删除属性

3确保通过添加驱动了上下文注释

原文链接:https://www.f2er.com/spring/431719.html

猜你在找的Spring相关文章