greetings all sometime in my app the logic forces me to use circular reference and i want to know how to enable this configuration in spring ?
A:
Spring has no problems with circular references. BeanA
can be wired with BeanB
, and vice versa. You only get problems with circular references if you introduce them yourself in your code.
If you have a specific issue, please elaborate.
skaffman
2010-07-15 11:12:12
I have Dao1 and Dao2:1-in Dao1 i autowire Dao22-in Dao2 i autowire Dao1my logic forces my to this and i am getting the excpetion of BeanCurrentlyInCreation coz of circular refernceand i want to allow this type of autowiring or do a workaround.
sword101
2010-07-15 11:19:55
@sword101: Please add these details to the original question, with concrete examples.
skaffman
2010-07-15 11:31:57
@sword101 In that case you should probably move that logic up into your service layer, and autowire both daos into the Service.
BrennaSoft
2010-07-15 13:49:38
+1
A:
Take a look at this article.
I would advice from the first option there. Circular dependencies are not a good sign and should be avoided. You can create a 3rd, helper class, for example.
The other two options are workarounds and will be harder to understand and debug later on.
Bozho
2010-07-15 12:00:11