How to call a service inside a service level

in my service

public class  MyServiceLayerImpl{   
    public void method1(){
       MyServicelayer.method();  //is this correct?
    }

    public void method2(){
    }

    @Autowired
    MyServiceInterface MyServiceLayer;
}

if I have a method inside the service level that needs to call another service inside the service level. I cannot use this._method because I use AOP for caching. In order for caching to work, I have to use it @Autowiredto get the service. So is the style above?

i below error

: org.springframework.beans.factory.BeanCreationException: bean 'com.company.iss.services.MyServiceLayerImpl # 85aedd': ; - org.springframework.beans.factory.BeanCreationException: autwire: com.company.iss.services.MyServicelayer com.company.iss.services.MyServiceLayerImpl.MyServiceLayer; - org.springframework.beans.factory.NoSuchBeanDefinitionException: bean [com.company.iss.services.MyServiceLayer]: [interface com.company.iss.services.MyServiceLayer]: 1 bean

+3
2

- .

, , bean. @Service ( ) , <bean> applicationContext.xml (. , spring 2)

: - , .

0

, :

public interface MasterService {
  void someMethod();
}

public class MasterServiceImpl implements MasterService {
  private OtherService otherService;

  public void someMethod() {
    this.otherService.someCallOnOtherService();
  }

  @Autowired
  public void setOtherService(OtherService otherService) {
    this.otherService = otherService;
  }
}

MasterServiceImpl, , OtherService. , XML- , .

, AOP , . Impl implement . .

+6

Source: https://habr.com/ru/post/1749535/


All Articles