弹簧用于使用完全合格的构造依赖性注入的名称

发布于 2025-02-03 23:11:08 字数 540 浏览 3 评论 0原文

我在一个项目中有多个模块(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).

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁微风不噪 2025-02-10 23:11:08

您可以使用@component(“ beanname”)@bean(“ beanname”), @named(“ beanname”)分配一个豆的自定义名称。默认情况下,Spring使用类名作为Bean名称。例如,您可以按照以下方式定义CustomAccountSapicOntroller类的bean名称:

@RestController("customAccountsApiControllerPrimary")
public class CustomAccountsApiController {
    
}

您可以从在这里

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:

@RestController("customAccountsApiControllerPrimary")
public class CustomAccountsApiController {
    
}

You can read more on bean name from here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文