jeudi 21 janvier 2021

Design pattern for Multiple services beans in SPring boot

I am working on a spring boot service project where we have multiple Spring Service beans which are autowired into each other.

For eg:

@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>

Most of the service beans are autowired into another service beans, along with auto-wiring their corresponding repository bean with some other beans (ModelMapper, some application context beans) Sometimes this leads to circular dependency problem and other times it fails in code quality check as there are more than 9 beans autowired via constructor injection.

My question is that is there a best practice or design pattern to structure these application spring beans?

Aucun commentaire:

Enregistrer un commentaire