expected at least 1 bean which qualifies as autowire candidate
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的更多相关文章
- 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问题.解决后在此记录一下. 解 ...
- 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 ...
- 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 ...
- springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题
Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...
- 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 ...
- mybatis expected at least 1 bean which qualifies as autowire candidate for this dependency
错误原因:没有引入相应mapper接口,导致spring没有找到依赖 解决方法一:使用注解的方法: 首先在spring配置文件中添加 <bean class="org.mybatis. ...
- 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整合的时候, 遇到了这个问题 说说我的问题吧!我在进行单元测试的时候,出现了这个错误,网上一查才知道是,配置文件中没有写扫描包信息.一看 ...
- 【java异常】expected at least 1 bean which qualifies as autowire candidate for this depende
1.查看接口实现类是否加入注解,如service.repository等 2.查看spring配置文件是否自动扫描包 <context:component-scan base-packag ...
- 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扫描注 ...
- 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
我出错的问题是: 检查:
随机推荐
- 工作流程调度器-DolphinScheduler
1.DolphinScheduler简介 Apache DolphinScheduler](https://dolphinscheduler.apache.org/)(目前处在孵化阶段)是一个分布式. ...
- javascript与css3动画学习笔记
当Html5,css3已渐渐成为主流的时候,我还非常习惯的用js去做一些简单的动画.因为在桌面浏览器上, 并非所有的都支持css3.用户也倒是很奇怪,用户习惯并不是每个用户都可以被培养.总有不少人会觉 ...
- RockyLinux9编译安装MySQL8
Linux版本: Rocky Linux release 9.5 (Blue Onyx) 1.下载 打开MySQL-Community-Server官方下载页面:https://downloads.m ...
- 解决线程安全问题的方式三:Lock锁 --- JDK5.0新增
Lock( 锁) 从JDK 5.0开始,Java提供了更强大的线程同步机制--通过显式定义同步锁对象来实现同步.同步锁使用Lock对象充当. java.util.concurrent.locks. ...
- C#/.NET/.NET Core技术前沿周刊 | 第 22 期(2025年1.13-1.19)
前言 C#/.NET/.NET Core技术前沿周刊,你的每周技术指南针!记录.追踪C#/.NET/.NET Core领域.生态的每周最新.最实用.最有价值的技术文章.社区动态.优质项目和学习资源等. ...
- flow pg walkthrough Intermediate
nmap nmap -p- -A -T4 -sS 192.168.114.104 Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-01-07 03 ...
- mysql事务中使用临时表
最近在使用存储过程完成晚上数据的定时汇总功能,其中需要在存储过程中启用事务,但是发现使用了create table语句后事务会自动提交这个语句前的语句,即便是这个语句后发生了错误进行了回滚. 测试语句 ...
- manim边学边做--局部变换
本次介绍的两个用于变换的动画类:TransformMatchingShapes和TransformMatchingTex. 它们的主要特点是对一组对象或一段文本进行局部变换,适用于复杂的图形或者文本的 ...
- 流程控制之增强for循环
语法 for (声明语句:表达式){ //代码语句} 实例: package com.yeyue.struct;public class ForDemo05 { public stati ...
- 2024年! kali高级配置加一键教程加前人的经验加后人的实践
2024年! kali高级配置加一键教程加前人的经验加后人的实践 记录一下配置kali的过程,方便下次需要直接复制粘贴 直接终端按照顺序输入就可以配置好 作者已踩点,请放心 kali更换国内源 sud ...