Question

I am trying to understand a web system using spring and I can not debug it. Now I am confused by the order of the XML initialization.

Support I have an web.xml which is like this:

<context-param>
    <param-name>contextConfigLocation</param-name>  
        <param-value>   
            classpath*:/com/pathA/**/applicationContext*.xml,classpath*:/com/pathB/**/applicationContext*.xml     
    </param-value>  
</context-param>

and in /com/pathA I have some xml files that define some beans with the same name. In /com/pathB I also have some xml files that define beans with the same name as in com/pathA's xml file.

I know that spring framework will use the last bean definition by default.But I can't find the order of the xml files initialization.

Here is the beans' definition:

/com/pathA/applicationContextOne.xml

<bean name="/testBean" class="com.TestActionOne">
</bean>

/com/pathA/applicationContextTwo.xml

<bean name="/testBean" class="com.TestActionTwo">
</bean>

/com/pathB/applicationContextThree.xml

<bean name="/testBean" class="com.TestActionThree">
</bean>

can anyone can tell me the initialization order of the differnet xml files in /com/pathA/

and the initialization order of the xml files between com/pathA/ and com/pathB?

Was it helpful?

Solution

I have written some samples in local pc (Windows and AIX)to simulate the initialization order and I found the result below.

1.the initialization order of files in different path depends on the order written in classpath*:/com/pathA/*/applicationContext.xml on my question, the [applicationContext*.xml] files in pathA will be initialized first and then in pathB.

2.the initialization order of files in the same path is the order of the file name

for example,if in pathA there are [applicatinContextOne.xml] and [applicationContextTwo.xml],then [applicatinContextOne.xml] will be initialized first and then [applicationContextTwo.xml].

I tried this under both Windows and AIX, and it returns the same result. Hope this will be helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top