Spring SMS Development Background We generally use Spring Struts iBATIS development mode, using Spring Standards Business Bean, when the project is large, face a bean naming conflict problem, like Struts, how to take a division, different modules Have your own namespace, will avoid a problem with a reselection of a BEAN configuration file when a few parallel developed subsystems or modules is shared. Simple Program The public bean, such as data sources, transaction management, ibatis or hibernate, an international resource file, etc. Here, you can see the elaborate scalability in Spring, and the constructor of ApplicationContext allows you to create through a parent instance.
Core classes ContextHelper, manager class as follows: public class ContextHelper {private static Map _contexts; private static ApplicationContext _rootContext; private static final String ROOT_CONTEXT = "conf / rootContext.xml"; static {_contexts = new HashMap (); try { _rootContext = new ClassPathXmlApplicationContext (ROOT_CONTEXT);} catch (Exception e) {throw new ContextException (e);}} public static synchronized Object getBean (String configName, String beanName) {ApplicationContext context = getApplicationContext (configName); Object bean = context. getBean (beanName); return bean;} // lazyload private static synchronized ApplicationContext getApplicationContext (String configName) {if (_contexts.containsKey (configName)) {return (ApplicationContext) _contexts.get (configName);} // here predetermined module Naming rules for profile string moduleconfigfile = "conf /" configname ".bean.xml"; string [] configs = {moduleconfigfile}; ap plicationContext context = new ClassPathXmlApplicationContext (configs, _rootContext); _contexts.put (configName, context); return context;} // message resources management public static String getMessage (String key, Object [] arg, Locale l) {return _rootContext. GetMessage (key, arg, l);}} What to pay attention to is, in each sub-module bean configuration file, if you reference the bacan in the root configuration, you cannot use the local property, please use bean = "datasource", start Didn't pay attention to this problem, the total report is wrong, I can't get correctly, I debugged for a long time. The above scheme is relatively simple, the main hidden dangers is that the communication problems between the modules, the current design is suitable for the case where the coupling of each module is small, and if there are some beans, it is necessary to share between several modules. It is necessary to mention the configuration in rootcontext.xml, which greatly increases the complexity of the root file.