弹簧用于使用完全合格的构造依赖性注入的名称
我在一个项目中有多个模块(Application + Library),它们包含相同名称(但不同的软件包)的服务类,这些类别将通过其各自的模块中的Lombok生成的构造函数注入。 当我启动应用程序模块时,Spring的classPathBeanDefinitionScanner
但是,请选择并提高BeanDefinitionStoreException
,因为它由于相同的bean名称而不在乎完全合格的类型名称。 是否有一个选项可以启用还需要类型匹配的豆类的更精确的分辨率? 这不是设计缺陷吗?我想念什么?
编辑:我相信名称取自Lombok的@requiredargsconstructor生成的构造函数,而服务类也是生成代码(Mapsstruct mappers)。
I have multiple modules (application + library) in a project and they contain service classes of same names (but different packages) that are to be injected thru Lombok generated constructors within their respective modules.
When I start the app module, the Spring's ClassPathBeanDefinitionScanner
however picks both and raises BeanDefinitionStoreException
because it detects both as a candidates, due to the same bean name and doesn't care about the fully qualified type name.
Is there an option to enable more precise resolution of the beans that also requires a type match?
Isn't this a design flaw? What am I missing?
Edit: Names, I believe, are taken from constructors generated by Lombok's @RequiredArgsConstructor, and service classes are also generated code (MapStruct mappers).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
@component(“ beanname”)
,@bean(“ beanname”)
, @named(“ beanname”)分配一个豆的自定义名称。默认情况下,Spring使用类名作为Bean名称。例如,您可以按照以下方式定义CustomAccountSapicOntroller类的bean名称:您可以从在这里
You can use
@Component("beanName")
,@Bean("beanName")
,@Named("beanName")
to assign a custom name to a bean. By default, spring uses the class name as the bean name. For Example, you can define bean name of your CustomAccountsApiController class as below:You can read more on bean name from here