zoukankan      html  css  js  c++  java
  • 解决@Autowire在springboot启动是报No qualifying bean的问题

    针对RedisTemplate封装了一个RedisUtils类,在调用时使用@Autowire注入此类,出现报错,内容如下

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.popmart.testcontainer.testcase.OmsTest':
    Unsatisfied dependency expressed through field 'redisUtils'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.popmart.config.redis.RedisUtils' available:
    expected at least 1 bean which qualifies as autowire candidate.
    Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    解决思路:

    1.根据保存分析原因:从报错信息无法扫描到redisUtils这个bean,如果@Autowire使用注释进行配置,则可能会缺少cn.itcast.crm.service.BaseDictService实现的注释(@Service或@Component等)。

    2.在RedisUtils类尝试着增加了@Service或@Component后问题解决,增加了@server注解后springboot启动可扫描到此bean。

  • 相关阅读:
    java学习笔记(4)多态
    scala学习笔记(1)
    java复习(3)继承下
    java复习(3)继承
    java复习(2)
    java中常见的异常种类
    数组的内存结构
    Castle ActiveRecord学习(一)简介
    OAuth2.0 Owin 授权问题
    将对象转为json,加入到HttpResponseMessage中
  • 原文地址:https://www.cnblogs.com/yull/p/14216315.html
Copyright © 2011-2022 走看看