Java – is the resource import order important in spring XML?

Suppose I import four resource files in the main configuration file of the application, as shown 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 instantiates it from bottom to top Figure how about the disconnected node? Does the order of import enter the game? Please explain

Solution

Yes, orders are important If you declare a bean in an imported file and then declare a bean with the same name in a subsequent imported file, the first bean declaration will be overwritten

Update: to solve your problem more directly, you can let the beans in the early import reference the beans in the subsequent import The order doesn't matter

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>