Back Forum Reply New

Using import for externalizing configuration.

Spring offers me two ways to externalize my configuration - use the import tag or pass an String array containing configuration file names while creating ApplicationContext.

I was able to locate some Spring best practices at pub/a/onjava/2...practices.html.  The author (in best practice 6) recommends the latter approach.

IMHO the import tag may be a good idea if I am able to break down my configuration in some hierarchy (the breakdown of configuration can be functional and there is one root configuration) also I dont have to modify my code if there is a need to add a new configuration. However if there are multiple top-level configurations then the 2nd option makes sense.

I would want to hear the community's take on this.

Indeed the import makes sense if you have a hierarchy of beans that can be aggregated somehow into particular files. I usually use an array (which should not have more then 10 xml files) to bootstrap spring as each file contains components of my applications - such as web, middle tier, jmx exposure.

SingletonBeanFactoryLocator provides another way to locate configuration locations - through a bean id representing the application context (or bean factory).  You can create arbitrary hierarchies of bean factories, and have independent subsets.  

You get the same effect from bean factor parent-child relations in a standard MVC web app with the ContextLoaderListener, but it is slightly less flexible and has a fixed hierarchy structure (one parent, one quot;middlequot; layer, and child contexts for each dispatcher servlet instance).  You have to specify the config locations for the quot;middlequot; tier application context
¥
Back Forum Reply New