No qualifying bean of type xxx' available 的一种解决方法
获取bean
Class beanClass = Class.forName(event.className);
FilterEvent filterEvent = (FilterEvent)BeansContext.getWebApplicationContext().getBean(beanClass);
event.className为要获取的类名
1 反复检查类名是否正确 ok
2 检查包扫描配置是否正确 ok
3 检查bean 是否已注册 ok 检查之后确认bean没有问题
@Service
public class GDXMMXExtendEx implements FilterEvent { @PostConstruct
public void init(){
System.out.println("==============?");
} }
4 在代码其他地方获取bean ok
5 对比能获取到bean 与不能获取到bean 时的差异 发现
beanClass上的classloader 不一致
能获取到bean的classloader 为RestartClassLoader
不能获取到bean的classloader 为AppClassLoader
查询classloader的区别 发现 devtools 可能会影响classloader
去掉这个插件 一切正常了
<!-- <dependencies>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-devtools</artifactId>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<!-- </dependencies>
补充:20191217
打包的时候将文件屏蔽掉了
我的bean 叫FIAPITestService 下面这个排除刚好排除掉
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.yaml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>ApplicationTest.class</exclude>
<exclude>**/*Test*.class</exclude>
<exclude>**/static/**</exclude>
<exclude>**/**/*.yaml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
参考:
1 https://blog.csdn.net/qq_36285899/article/details/82867768
No qualifying bean of type xxx' available 的一种解决方法的更多相关文章
- spring注入时报错::No qualifying bean of type 'xxx.xxMapper'
做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Auto ...
- 关于No qualifying bean of type [XXX.XXX] found for dependency 的一次记录
异常开始于spring+springmvc+mybatis 注解配置,启动tomcat服务器出现No qualifying bean of type [com.***.service] found f ...
- Cannot load module file xxx.iml的两种解决方法
一. 一种是点击左上角File,然后点击Invalidate Caches / Restart...,弹出对话框再点击Invalidate and Restart等待工程重新加载,问题就解决了. 二. ...
- Spring mvc 报错:No qualifying bean of type [java.lang.String] found for dependency:
具体错误: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean w ...
- No qualifying bean of type [com.shyy.web.service.TreeMapper] found for dependency
异常信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sp ...
- 开发错误日志之No matching bean of type [xxx] found for dependency
No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...
- Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
1. Overview In this article, we are discussing the Springorg.springframework.beans.factory.NoSuchBea ...
- 【Spring】手动获取spring容器对象时,报no qualifying bean of type is defined
手动获取容器对象时,报no qualifying bean of type is defined, 经过调查,发现手动获取的时候,该类所在的包必须经过spring容器初始化. 1.SpringConf ...
- Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]
环境为Spring + Spring mvc + mybatis:其中Spring版本为4.1.4 spring配置文件: <?xml version="1.0" encod ...
随机推荐
- django搭建一个小型的服务器运维网站
前言 不管是运维还是开发抑或是测试,工作中不免会和Linux服务器打交道,常见的操作譬如:查看CPU或内存状态.查看和修改服务器时间.查看或者修改服务器配置文件.实时查看或回看系统的日志.重启服务 ...
- 修改docker默认网段
一. 修改普通docker run启动的容器的网段 https://blog.51cto.com/13670314/2345518?source=dra https://blog.csdn.net/w ...
- navigation ObtacleCostFunction源码分析
ObtacleCostFunction 定义了一个ObstacleCostFunction类,继承自Trajectory类,Trajectory类有8个类参 总共有8个类参 double xv_,yv ...
- Java基础数据类型小结
1. 记忆中的数据类型: 记忆中java一共有八种基础数据:boolean,byte,char,int,long,float,double,还有一种记不起来. 他们的长度分别为: 他们的用处 ...
- Oracle Flashback Database
Oracle Flashback Database Ensure that the prerequisites described in Prerequisites of Flashback Data ...
- 【C++进阶:移位运算符的用法】
数据在计算机中以补码存储 移位运算符:<< 左移运算符 >> 右移运算符 一丶 << 左移运算符 移位规则:左边抛弃,右边补零 int num=10; num& ...
- Mac开机自动运行shell脚本
1.首先写一个sh脚本,比如: cd ~/Documents mkdir haha 代码很简单,进入Documents文件夹,建立haha目录,保存为run.sh 2.修改run.sh权限 sudo ...
- *args 和**kwargs 的理解以及 函数的参数的总结
一:函数参数的理解: def 函数名(函数参数): 函数体 例如: def func(a): # a 是形参 print(a) func(123) # 123 是实参 形参又分为: 关键字参数,位置参 ...
- git 还原、恢复、回退
通过git revert来实现线主干代码的回滚.如下命令 对于 merge类型的commit对象,还需要"-m"参数 git revert -m 1 commit-id 对于普通 ...
- 搭建 Git 服务器(基于 CentOS 7)
服务器上的-Git-架设服务器-官网参考 对于规模比较小的团队,可以直接搭建 Git 服务器,逐个收集研发同学的证书配置进来即可.如果团队规模比较大,可以直接采用 GitLab.Drone 等现成的带 ...