解决Error creating bean with name XXX: Injection of resource dependencies failed

25 篇文章 2 订阅
9 篇文章 0 订阅

在这里插入图片描述解决SSH整合时出现的错误,错误如上图所示。

该错误是因为Mybatis中需要的注解,spring没有检测到此注解信息。

错误原因可能有四处:

(1):web.xml没有配置spring的上下文环境和核心的监听器

解决办法:
在web.xml添加

  <!--spring的上下文-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-common.xml</param-value>
  </context-param>
  <!--spring的核心监听器-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

(2):SpringMVC的核心配置文件中没有正确配置扫描仪,如果项目需要用到注解的包,那么这个包都需要配置注解扫描器

解决办法:
第一种写法:在springmvc-config.xml添加:

	<context:component-scan base-package="com.zs.controller" />
	<context:component-scan base-package="com.zs.services" />

第二种写法:在springmvc-config.xml添加(com.zs包下的所有类都能扫描到):

    <context:component-scan base-package="com.zs"></context:component-scan>

(3):正确的配置注解扫描器,也需要在相应的类上标明该类的注解,如果不标明,项目启动的时候就无法识别该类的注解,然后在别处调用该类,也会报此错。

解决办法:
为需要注解的类添加自动扫描@Service、 @Controller等
在这里插入图片描述
具体需要哪一种,请看官方文档解释:Spring 2.5引入了更多典型化注解(stereotype annotations):

@Component、@Service和 @Controller。@Component是所有受Spring管理组件的通用形式;而@Repository、@Service和 @Controller则是@Component的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。也就是说,你能用@Component来注解你的组件类,但如果用@Repository、@Service 或@Controller来注解它们,你的类也许能更好地被工具处理,或与切面进行关联。例如,这些典型化注解可以成为理想的切入点目标。当然,在Spring Framework以后的版本中, @Repository、@Service和 @Controller也许还能携带更多语义。如此一来,如果你正在考虑服务层中是该用@Component还是@Service,那@Service显然是更好的选择。同样的,就像前面说的那样, @Repository已经能在持久化层中进行异常转换时被作为标记使用了。”

(4):前面几种可能出现的情况你都没有发生,那么可能是你在配置多个自动注解的类,自动注解的类的唯一标识符重复。

解决办法:将每个需要自动注解类的标识符修改为不同的,因为在调用的时候,不是类型@Autowired自动注入,则是 @Resource(name = “studentService”,type = com.zs.services.Impl.StudentServiceImpl.class)这种方式注入,是根据name来找到注解类的,所以name必须不同。
在这里插入图片描述

一般情况下是这几个地方出了错,细心检查一下哦~

说在最后的话:编写实属不易,若喜欢或者对你有帮助记得点赞+关注或者收藏哦~

  • 29
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
引用:出现No qualifying bean of type [com...dao.InfoDao] found for :错误 链2:Error creating bean with name ‘userServiceImpl’: Injection of autowired dependencies failed 链3:SPRING MVC 配置报错ERROR CREATING BEAN WITH NAME ‘USERCONTROLLER’: INJECTION OF RESOURCE DEPENDENCIES 链4:解决Error creating bean with name XXX: Injection of resource dependencies failed 。 引用:Error creating bean with name 'projectReservePoolController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xuci.apply.service.IProjectReservePoolService' available: expected at least 1 bean which qualifies as autowire candidate. 。 引用:报错: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookDao' defined in file [D:\code\ideaProjectsCode\spring\ssm\target\ssm-1.0-SNAPSHOT\WEB-INF\classes\com\nxg\dao\BookDao.class]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to required type 'org.mybatis.spring.SqlSessionTemplate' for property 'sqlSessionTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to required type 'org.mybatis.spring.SqlSessionTemplate' for property 'sqlSessionTemplate': 。 根据引用和引用的错误信息,"Error creating bean with name 'carController': Injection of resource dependencies failed"表示在创建名为'carController'的bean时,注入资源的依赖项失败。这种错误通常出现在Spring的依赖注入中,可能是由于找不到或无法匹配所需类型的bean而导致的。在这种情况下,可能需要检查bean的配置和依赖项的注入方式,确保正确配置和匹配。另外,还需要检查所需类型的bean是否已经正确定义和可用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ssm之Error creating bean with name ‘bookServiceImpl‘: Injection of resource dependencies failed;](https://blog.csdn.net/nxg0916/article/details/126235159)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [springboot:Error creating bean with name ‘XXXController‘: Injection of resource dependencies failed](https://blog.csdn.net/qq_43790218/article/details/127878908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值