Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Load files in <import resource=.../> only once [SPR-1142] #5845
If I load now an application context which has "file1.xml" and "file2.xml" as config locations, the file "common-config.xml" will be loaded twice. I suggest to remember the url of already loaded config files.
67 votes, 52 watchers
Sébastien Launay commented
Because this issue is opened for many years I was thinking of proposing a solution because our spring configuration uses lots of XML files decomposed with imports and lots of AOP configuration :) and computing unused bean definitions is expensive at runtime.
So here is a patch for loading application context resources only once against the trunk.
This feature is enabled by setting the bean property
I do not know if this is interesting but I do not modified JavaConfig classes to reflect such behavior with
Let me know if this approach is right or if I need to go in another direction.
Tim Ducheyne commented
Just a small remark about the patch:
There is a problem with the hashcode and equals implementation of URL
Felix Simmendinger commented
This behaviour is espacially then problematic, because BPP are executed multiple times if they are declared as anonymous beans or defined via a namespace eg. <context:property-placeholder ... . For the latter it is impossible to define an id. Since there are special beans that can be defined only once eg. the multipartresolver this problem means you cannot hide the multipartresolver in a xml file hierarchy as it may be loaded twice.
Dale Wyttenbach commented
It typically happens indirectly:
Andy Schäfer commented
Some additional thoughts to the comment of Dale Wyttenbach in answer to Keith Donald:
In order to ensure, that C isn't loaded twice we import in the topmost application.spring.xml all configurations (A, B, C and D). So the import of C is done only there, nowhere else.
Maybe there are approaches better than the one I outlined (interested to hear of them), but this issue would be handy to solve the problem in a simple way:
Since this issue had been logged around 9 years back and is still unresolved, I was just wondering if there is some major reason for it?