【发布时间】:2021-04-26 02:36:18
【问题描述】:
我正在开发一个 Spring Boot 服务项目,其中我们有多个 Spring Service bean,它们相互自动连接。
例如:
@Service
public class Service1
@Autowire
Service2, Service3
.
.
.
@Service
public class Service5
@Autowire
Service 4, Service 1
@Repository
public interface Service1Repository extends JpaRepository<Entity1, UUID>
.
.
.
@Repository
public interface Service5Repository extends JpaRepository<Entity5, UUID>
大多数服务 bean 都自动装配到另一个服务 bean 中,同时将它们对应的存储库 bean 与其他一些 bean(ModelMapper、一些应用程序上下文 bean)自动装配在一起 有时这会导致循环依赖问题,有时会导致代码质量检查失败,因为通过构造函数注入自动装配的 bean 超过 9 个。
我的问题是,有没有最佳实践或设计模式来构建这些应用程序 spring bean?
【问题讨论】:
标签: java spring spring-boot design-patterns microservices