• org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'tokenService';

  • nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xx.common.security.service.TokenService' available: expected at least 1 bean which qualifies as autowire candidate.

  • 原因@SpringBootApplication只会扫描本包子包下的bean对象,由于TokenService和RedisService与鉴权部分路径不同,因为分别在common模块的两个子模块中(包名肯定不一样,虽然写成一样不会出现这样的问题,但是一般又不会写成一样)。所以扫描不到。

  • 解决方法

    • 在common子模块(需要在其他地方使用的工具类所在模块中)的resources下创建文件META-INF/spring.factories手动注入

      org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
      com.example.*(最好具体到类,下面注解同)
    • 或者在启动类上添加

      @SpringBootApplication(scanBasePackages={"com.example.*"})

    其他博客有看到会出现一些问题,还是建议在多模块中,那些工具类什么的,还是使用第一种解决方法。

    注意:启动类上加了@SpringBootApplication(basePackages = {})这个注解会导致controller扫描不到导致的,因为如果加了这个注解就不会扫描所在的包及子包的文件,需要将controller所在的包加入到注解@SpringBootApplication的大括号中

expected at least 1 bean which qualifies as autowire candidate的更多相关文章

  1. Caused by:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type "" available: expected at least 1 bean which qualifies as autowire candidate

    项目使用spring, mybatis.因为分了多个模块,所以会这个模块引用了其它模块的现在,结果使用Junit测试的时候发现有两个模块不能自动注入dao和service问题.解决后在此记录一下. 解 ...

  2. spring加载bean报错:expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

    看具体报错日志: 警告: Unable to proxy interface-implementing method [public final void cn.wlf.selection.proto ...

  3. NoSuchBeanDefinitionException:No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

    报错如下: NoSuchBeanDefinitionException:No qualifying bean of type   found for dependency: expected at l ...

  4. springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题

    Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...

  5. No matching bean of type [xx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency

    这个看起来很弱爆的问题其实是因为其他的配置文件中已经出现了为xx定义好的注入.如果用@Autowired就会得到上面的错误 , 但是用@Resource的时候就会看到类似下面的错误 Bean name ...

  6. mybatis expected at least 1 bean which qualifies as autowire candidate for this dependency

    错误原因:没有引入相应mapper接口,导致spring没有找到依赖 解决方法一:使用注解的方法: 首先在spring配置文件中添加 <bean class="org.mybatis. ...

  7. NoSuchBeanDefinitionException: No qualifying bean of type 'com.bj186.ssm.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate

    在搭建SSM spring springmvc  mybatis整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...

  8. 【java异常】expected at least 1 bean which qualifies as autowire candidate for this depende

    1.查看接口实现类是否加入注解,如service.repository等 2.查看spring配置文件是否自动扫描包    <context:component-scan base-packag ...

  9. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut

    spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注 ...

  10. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.thinkplatform.dao.UserLogDao' available: expected at least 1 bean which qualifies as autowi

    我出错的问题是: 检查:

随机推荐

  1. biancheng-NumPy教程

    目录http://c.biancheng.net/numpy/ 1NumPy是什么2NumPy下载与安装3NumPy ndarray对象4NumPy数据类型5NumPy数组属性6Numpy创建数组7N ...

  2. linux内核 list_for_each_entry

    1. linux内核中的list用法 在linus内核中,list一般这样使用: struct list_head { struct list_head *priv; struct list_head ...

  3. 如何分析jmeter性能测试数据

    1.jmeter插件 https://blog.csdn.net/weixin_39430584/article/details/80947093 http://www.doc88.com/p-214 ...

  4. mysql 使用 ibd 恢复数据

    分四步: 1. 按照ibd对应的表结构,创建新表: 2. 执行: ALTER TABLE `t_健忘就多写博客` DISCARD TABLESPACE; 或者 停止mysql服务后,删除对应的 xxx ...

  5. 共促国产AI生态繁荣,天翼云重磅发布魔乐开发者社区

    8月29日,以"聚数乘云,天翼赋能数字经济新生态"为主题的天翼云中国行·贵州站活动顺利举办.会上,天翼云与华为联合打造的魔乐(Modelers)开发者社区正式上线发布.通过建设社区 ...

  6. FOFA 图标哈希值大全

    FOFA 图标哈希值大全 服务 图标 哈希值 默认端口 Atlassian Crowd icon_hash="-1231308448" 8095 CouchDB icon_hash ...

  7. Maven入门,读完这篇就够了

    Maven 项⽬⽣命周期 Maven从项⽬的三个不同的⻆度,定义了三套⽣命周期,三套⽣命周期是相互独⽴的,它们之间不会相互影响. 清理⽣命周期(Clean Lifecycle):该⽣命周期负责清理项⽬ ...

  8. Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版

    Deepseek卡的问题已经有几周了,还有同学没有解决这个问题? 今天就来教大家如何白嫖阿里云的Deepseek-R1满血版,新用户享受100万token额度,相当的富裕,可以随便用了.并且还配用AP ...

  9. [开源自荐] Catime 不一样的计时器(番茄时钟),非常欢迎反馈

    Catime 一款简洁的 Windows 倒计时工具,具有透明界面和丰富的自定义选项. Github:https://github.com/vladelaina/Catime 特点 极简设计: 透明界 ...

  10. java推送企业微信消息

    <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcl ...