【发布时间】:2018-08-05 23:05:07
【问题描述】:
我有一组要注入到 Spring 应用程序上下文中的类。但是,这些类只能保证使用我编写的一组注释中的一个进行注释 - 即我可以假设它将使用 @MyAnnotation 进行注释,而不是 @Component。
但是,@MyAnnotation 构成了我项目的 API 的一部分,我不想声明此 API 对 Spring 的显式依赖。因此,我不能用 @Component 注释 @MyAnnotation 以使其被 Spring 传递地拾取。
有没有办法告诉 Spring 在其类路径扫描中额外包含 @MyAnnotation 而不将此依赖项添加到我的 API?
目前我正在操作 bean 定义注册表以“手动”添加每个使用 @MyAnnotation 注释的类,但我更愿意依赖 Spring 的内置支持。
提前致谢。
【问题讨论】:
-
您是否已经使用 BeanDefinationProcessor 手动将它们加载到上下文中?
标签: java spring spring-boot dependency-injection