Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does resource import order matters in Spring XML?

Tags:

java

spring

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.

like image 994
Sathish Kumar Avatar asked Nov 04 '15 07:11

Sathish Kumar


1 Answers

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.

like image 81
Ken Geis Avatar answered Oct 02 '22 01:10

Ken Geis