Reputation: 87
Lets say I import four resource files in my application's main configuration file as below,
<import resource="db-config.xml"/>
<import resource="cache-config.xml"/>
<import resource="sec-config.xml"/>
<import resource="rajnikanth.xml"/>
<!-- My app beans here -->
My understanding is that Spring creates a DAG and instantiate bottom-up. What about the disconnected nodes in the graph? Does order of import come into the play? Please explain.
Upvotes: 6
Views: 8094
Reputation: 922
Yes, order matters. If you declare a bean in one imported file and then declare a bean with the same name in a subsequently imported file, the first bean declaration is overridden.
UPDATE: To more directly address your question, it is fine to have beans in earlier imports refer to beans in later imports. Order does not matter in this way.
Upvotes: 11