Problems with spring circular referencing

Source: Internet
Author: User

For a long time did not write technology paste, these two days by spring's circular reference killed, issued a note.

A few days ago, the project structure was adjusted to embed my project code in another project, and then the cups had the following symptoms:

Bean with name ' Xxxservice ' have been injected into other beans [xxxservice] in its raw version as part of a circular refer ence, but had eventually been wrapped. This means, said other beans does not use the final version of the Bean. This was often the result of over-eager type matching–consider using ' Getbeannamesoftype ' with the ' alloweagerinit ' flag Turned off, for example.

The spring version used is 2.5.6, and has encountered this problem before, it is true that the code is designed to be more coupled, and the related logic is split to be resolved. These two days this question, no matter how I disassemble all follows, is not a simple a->b,b->a circular reference, but the deep logic coupling, to decouple more difficult, explained in the design stage has the room to improve. The weird thing is, before the integration of another project is not to throw this error, the visible problem may be in the new project after the integration of the configuration file, a simple analysis or not to the point, and began to enable Google. Juergen Hoeller says:

This is probably a consequence of the bean initialization order has changed, in combination with auto-proxying and Mayb E a pointcut is too broad.

Then he gives the solution, has a parameter setallowrawinjectiondespitewrapping, the default is False, set it to true. The code is as follows:

<span style= "font-size:18px" >Publicclassextends  xmlwebapplicationcontext {        @Override       protected defaultlistablebeanfactory createbeanfactory () {          =  Super. Createbeanfactory ();          Beanfactory.setallowrawinjectiondespitewrapping (true);           return beanfactory;      }    } </span>

Then, in the Web. XML configuration, enable this context,

<spanstyle= "font-size:18px"><Context-param>          <Param-name>Contextclass</Param-name>          <Param-value>Xxx. Mywebapplicationcontext</Param-value>  </Context-param></span>

And then it's ready.

Of course, this is only a temporary solution, the root cause of the problem must be solved from the point of view of design, as far as possible to design decoupled code, to be improved, write this article is because I searched a lot on the internet, found are not very clear, according to the error message earlier in this article can not find a better answer. On the other hand, as spring grows larger and the parameters are complex, only the developer knows what each one means and how to set it, and it is not the spring of the year that pursued simplicity.

Problems with spring circular referencing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.