@ComponentScan 无法扫描隔离类加载器中的类?使用 ImportCustomBeanDefinitionRegistrar 解决
@ComponentScan 用于扫描指定的包或类,并将它们注册为 Spring 的 Bean。如果你的类被隔离在一个特定的类加载器中,那么默认情况下,@ComponentScan 无法扫描到这些类。
如果你需要扫描隔离类加载器中的类,可以考虑使用 ImportCustomBeanDefinitionRegistrar 来实现。该接口可以让你自定义 BeanDefinition 的注册逻辑,从而实现对隔离类加载器中的类的扫描和注册。
具体实现可以参考 Spring 官方文档中的 Importing additional configuration classes 部分。
原文地址: https://www.cveoy.top/t/topic/lIjg 著作权归作者所有。请勿转载和采集!