Spring-Spring CoreNo Comments

In this tutorial, I will show you how to using multiple configuration files. If you don’t know how to inject dependency in Spring configuration file, just checked my previous post here Spring DI

  • Call multiple configuration files

In large project,  we would want to split Spring bean’s configuration file into multiple files for easier maintainability and modular

Here is how to init all of them :

InitClass :

By that, Spring will load all of configuration files and init beans inside them.

  • Call a single configuration file but contain many other files

What if you only want to load just one file, but this file will contain other configuration files ? (Notice that they can be put in different folders)

spring-module.xml :

And just init all of them by init only single configuration file :

InitClass :

  • Can beans in different configuration files call to each other ?

Yes they can,  just injected them like normal :

spring-moduleA.xml :

spring-moduleB.xml :

Actually, the ‘ref’ tag can access to a bean either in same or different XML files, if you can ensure they are in same file you should use the ‘local’ attribute for the project readability.

That’s your choice!




Be the first to post a comment.

Add a comment