Spring Ioc 要点:之一容器的初始化
实例化容器
ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml", "applicationContext-part2.xml"});// of course, an ApplicationContext is just a BeanFactoryBeanFactory factory = (BeanFactory) context;<beans><import resource="services.xml"/> <import resource="resources/messageSource.xml"/> <import resource="/resources/themeSource.xml"/> <bean id="bean1" name="code"><context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value></context-param><listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class></listener><!-- or use the ContextLoaderServlet instead of the above listener<servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet>-->
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="..." name="code"><alias name="fromName" alias="toName"/>
<alias name="componentA-dataSource" alias="componentB-dataSource"/><alias name="componentA-dataSource" alias="myApp-dataSource" />这样一来,每个组件及主程序就可通过唯一名字来引用同一个数据源而互不干扰。