获取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>

参考:

https://blog.csdn.net/qq_36285899/article/details/82867768

No qualifying bean of type xxx' available 的一种解决方法的更多相关文章

  1. spring注入时报错::No qualifying bean of type 'xxx.xxMapper'

    做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Auto ...

  2. 关于No qualifying bean of type [XXX.XXX] found for dependency 的一次记录

    异常开始于spring+springmvc+mybatis 注解配置,启动tomcat服务器出现No qualifying bean of type [com.***.service] found f ...

  3. Cannot load module file xxx.iml的两种解决方法

    一. 一种是点击左上角File,然后点击Invalidate Caches / Restart...,弹出对话框再点击Invalidate and Restart等待工程重新加载,问题就解决了. 二. ...

  4. 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 ...

  5. 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 ...

  6. 开发错误日志之No matching bean of type [xxx] found for dependency

    No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...

  7. 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 ...

  8. 【Spring】手动获取spring容器对象时,报no qualifying bean of type is defined

    手动获取容器对象时,报no qualifying bean of type is defined, 经过调查,发现手动获取的时候,该类所在的包必须经过spring容器初始化. 1.SpringConf ...

  9. Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]

    环境为Spring + Spring mvc + mybatis:其中Spring版本为4.1.4 spring配置文件: <?xml version="1.0" encod ...

随机推荐

  1. Count on a tree(树上路径第K小)

    题目链接:https://www.spoj.com/problems/COT/en/ 题意:求树上A,B两点路径上第K小的数 思路:主席树实际上是维护的一个前缀和,而前缀和不一定要出现在一个线性表上. ...

  2. 9-10 November

    cout 和 printf 在 C++ 中的实现:四舍六入五随缘.比如 printf("%.0lf\n", x=1.5) => 1. 标准做法:printf("%d ...

  3. 8 Django模型层(1)

    知识预览 ore简介 单表操作 章节作业 ore简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可 ...

  4. git 指定从其他分支拉取commit

    git cherry-pick commit-id  (github 上的短号)

  5. 二十五、python中pickle序列学习(仅python语言中有)

    1.pickle序列介绍:提供4个关键字:dumps,dump,loads,load 语法:f.write(pickle.dumps(dict))=pickle.dump(dict,f) " ...

  6. error: exportArchive: You don’t have permission to save the file “HelloWorld.ipa” in the folder “HelloWorld”.

    成功clean环境和生成archive文件之后,最后一步导出ipa包,遇到了权限问题: you don’t have permission to save the file “HelloWorld.i ...

  7. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_2_对象的序列化流_ObjectOutputStream

    创建person对象.生成构造方法全参和无参.getter和setter 抛出异常:没有序列化异常 接口的源码 啥都没有.就起到一个标记的作用 用二进制存的

  8. 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_08 Map集合_7_HashMap存储自定义类型键值

    自定义类型做key值.必须要重写hashCode和equals方法 创建pserson类 有name个age两个成员变量.重写toString方法 key有重复,会被新的value值替换掉. key值 ...

  9. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_01 File类_4_File类的构造方法

    学习一个类先学习构造方法和静态方法 重写了Object类的toString方法 文件夹结尾 相对路径 第二个构造方法 两个路径组装到了一起 加上双斜线 换成d盘 第三个构造 第一个参数是一个File对 ...

  10. 《图解设计模式》读书笔记7-1 facade模式

    目录 1. Facade模式简介 2. 示例程序 2.1 类图 2.2 程序 3.角色和类图 4.思路拓展 1. Facade模式简介 开发程序的过程中,随着时间的推移,类会越来越多,调用关系会越来越 ...