Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have multiple context files. Requirement is: one particular Bean (which makes some configuration changes) to be initialized first among rest of beans.

Is there a way to get this bean loaded first?

One option is using depends-on` attribute. But that would require updating all the rest of the beans, thus seems not to be best solution.

Do we have better options?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

IMHO you should wait until they fix https://jira.spring.io/browse/SPR-3948

One probable way is to use depends-on attribute. But again, I don't want to add this attribute in all the rest of the beans (this is probably the last resort for me).

Actually, you don't need to use depends-on on EACH AND EVERY BEAN in each and every applicationContext.xml.

Use <import /> in all "lower-lvel" applicationContext.xml to import the topmost applicationContext.xml.

And use depends-on attribute in each and ever bean definition only in topmost applicationContext.xml, except the <bean /> that you wanna load first.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...