@ComponentScan 是用来扫描指定的包或类,并将其注册为 Spring 的 Bean。如果你的类是被隔离在一个特定的 classloader 中,那么默认情况下,@ComponentScan 是无法扫描到这些类的。

如果你需要扫描隔离类加载器中的类,可以考虑使用 ImportCustomBeanDefinitionRegistrar 来实现。该接口可以让你自定义 BeanDefinition 的注册逻辑,从而实现对隔离类加载器中的类的扫描和注册。

具体实现可以参考 Spring 官方文档中的 Importing additional configuration classes 部分。

为什么@ComponentScan 无法扫描到我隔离的classloader中的类? 是不是应该用 ImportCustomBeanDefinitionRegistrar ?

原文地址: https://www.cveoy.top/t/topic/vDN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录