For a large application, multiple configuration files may exist. We can specify these configuration files through the String array when starting Spring containers.
Spring can also use <import> to introduce multiple configuration files into one file, and integrate these configuration files, so that when starting Spring container, you only need to specify this main configuration file. For example, the following main configuration file:
<import resource="classpath:beans2.xml"/><bean id="author"/>
Assuming that the Book class is already configured in beans2.xml, then the Spring container can load these two bean information through this main configuration file O(∩_∩)O Haha~
If a configuration file a.xml refers to a bean in b.xml, it does not necessarily need to import b.xml through import. It only needs to ensure that when starting the Spring container, a.xml and b.xml are both in the configuration file list.
The difference between these two configuration methods is that if b.xml is introduced using import in a.xml, it is equivalent to a.xml file containing all the information of these two configuration files. Therefore, the Spring container only needs to load the a.xml file; otherwise, two configuration files need to be loaded at the same time when Spring starts, so that the two configuration files are merged in memory.
We can introduce multiple external configuration files through <import>, and the resource attribute supports Spring's standard resource path.
In order to prevent configuration file resource competition during development, large applications often have direct independent configuration files for easy splitting of modules. We can provide an integrated configuration file at the application level, integrating each module through <import>. In this way, when starting the container, you only need to load the integrated configuration file
Summarize
The above is the method of integrating multiple configuration files by Spring introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time!