spring autowired aop circular dependency

后端 未结 4 400
萌比男神i
萌比男神i 2021-01-31 09:07

I\'m using java config with @ComponentScanin order to initialize my beans and @EnableAspectJAutoProxy(proxyTargetClass=true)to use cglib proxies.

4条回答
  •  时光说笑
    2021-01-31 09:14

    I have same issue and I solved this issue:

    1. I identified which @Autowired property is reason for circular dependency.

      Eg:

      @Autowired
      private TestService testService;
      

      (Tips to identified just try to comment and find out which property is reason to break the application)

    2. Once identified just use @Lazy on top of this @Autowired variable.

      Eg :

      @Lazy
      @Autowired
      private TestService testService;
      

      And Application worked smoothly.

提交回复
热议问题