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;
    
    // ...

}

Advertisement

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement