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
我出错的问题是: 检查:
随机推荐
- Elasticsearch应用介绍
Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引擎.当然 Elasticsearch 并不仅仅是 Luce ...
- NTRU
介绍 NTRU(Number Theory Research Unit),NTRU是一个带有专利保护的开源公开密钥加密系统,使用基于格的加密算法来加密数据.它包括两部分算法:NTRUEncrypt用来 ...
- bkce-6.0.4基础环境部署简述
1.概述 1.1.相关网站: # 蓝鲸软件包下载:https://bk.tencent.com/download/ # 蓝鲸社区版软件包下载https://bk.tencent.com/downloa ...
- 载誉而归!天翼云荣获第23届中国IT用户满意度大会多项殊荣
10月25日,2024第23届中国IT用户满意度大会暨首届工业产品满意度交流会在北京举行.现场揭晓"2024中国IT用户满意度征集结果",天翼云凭借领先的产品技术.完善的客户服务以 ...
- Spring AI + DeepSeek:提升业务流程的智能推理利器
今天,我们将深入探讨如何利用DeepSeek来真正解决我们当前面临的一些问题.具体来说,今天我们仍然会将DeepSeek接入到Spring AI中进行利用.需要注意的是,虽然DeepSeek目前主要作 ...
- shell 变量的运算、保存硬件信息脚本
变量的数学运算 方法一:expr ##加减乘除 [root@localhost ~]# num1=10[root@localhost ~]# num2=16[root@localhost ~]# ex ...
- 管理虚拟机(libvirt)
给我的理解就是与用户交互的"显示器" [root@kvm1 ~]# systemctl status libvirtd [root@kvm1 ~]# virsh virsh # l ...
- 从0搭建Vue3组件库(一): 开篇
前言 这是从0搭建Vue3组件库系列文章第一篇文章,这个系列我曾经写过多篇文章,但是写完之后回过头来再看里面有很多遗漏以及不足之处,所以决定重新梳理这个系列,并从头开始搭建一个完整的Vue3组件库工程 ...
- Java中编译期异常和运行期异常的区别
在Java中,异常分为运行期异常(Runtime Exception)和编译期异常(Checked Exception),两者的核心区别在于 编译器是否强制要求处理.以下是它们的详细对比: 1. 定义 ...
- Nginx - [02] 安装部署&配置
官网下载地址:http://nginx.org/en/download.html 001 || 安装[windows] 解压之后,在命令提示符窗口启动nginx.exe 在浏览器访问80端口:loca ...