登录
首页 >  文章 >  java教程

Spring Cloud Alibaba中如何集中管理Common模块的Entity、Mapper和Service?

时间:2024-12-10 17:55:06 233浏览 收藏

“纵有疾风来,人生不言弃”,这句话送给正在学习文章的朋友们,也希望在阅读本文《Spring Cloud Alibaba中如何集中管理Common模块的Entity、Mapper和Service?》后,能够真的帮助到大家。我也会在后续的文章中,陆续更新文章相关的技术文章,有好的建议欢迎大家在评论留言,非常感谢!

Spring Cloud Alibaba中如何集中管理Common模块的Entity、Mapper和Service?

想将其他模块的 Entity、Mapper 和 Service 集中到 Common 模块中?

使用 Spring Cloud Alibaba 2021.0.1 Spring Boot 2.6.4,如何让其他业务模块的 Entity、Mapper 和 Service 都集中管理在 Common 模块中?

问题的尝试和解决

  • 扫描 Common 模块中的包会报错:org.springframework.beans.factory.BeanCreationException: ...
  • 添加 @ComponentScan 扫描所有包也会报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean...

正确的配置

根据描述的情况,在 merchant 模块和 supply 模块中,配置如下:

  • spring 包扫描:scanBasePackages = "com.quanneng"
  • mapper 接口配置:@MapperScan("com.quanneng.mapper")
  • swagger 接口扫描配置:按照swagger的配置

此外,统一异常处理只允许存在于一个模块中。

其他建议

将 Common 模块编写成一个 Spring-Boot-Starter 也是一个可行的方案,这样可以避免包扫描问题。

以上就是《Spring Cloud Alibaba中如何集中管理Common模块的Entity、Mapper和Service?》的详细内容,更多关于的资料请关注golang学习网公众号!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>