Skip to content
Advertisement

Spring boot – @Service class calling another @Service class

Is it fine to have a @Service annotated class calling another @Service annotated class? Or it is a bad practice?

Eg.:

@Service
public class MyService {

    // ...
    
    @Autowired
    private MyOtherService myOtherService;
    
    // ...

}

EDIT – after 3 years

It’s ok to have dependencies from one service to another. This is mainly because of reusability. If circular dependencies happen between two services from the same module, that’s ok.

You should only avoid circular dependencies between modules.

Answer

It is not any restriction calling a service from another one. Unless you make circular dependency between services.

Circular dependency : https://en.wikipedia.org/wiki/Circular_dependency

Circular dependency in spring : https://www.baeldung.com/circular-dependencies-in-spring

Advertisement