How to solve it with circle-dependency setter injection and @Lazy

34 Views Asked by At

Recently, a circular-dependency error occurred in the project and I solved it this way, but I did not fully understand how this code works. What exactly did @Lazy annotation do here? Or how did it inject BeanB to form BeanA?

public class BeanA { 
private BeanB beanB; 

@Autowired 
public void setBeanB(BeanB beanB) { 
    this.beanB = beanB; 
} 

}

public class BeanB { 
private BeanA beanA; 

@Autowired 
@Lazy 
public void setBeanA(BeanA beanA) { 
    this.beanA = beanA; 
} 

}

Advance thanks.......

0

There are 0 best solutions below