拆分Spring配置文件
多个参数方式:
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml",
"applicationContext-dap.xml",
"applicationContext-service.xml");
数组参数方式:
String[] configs = {"applicationContext.xml",
"applicationContext-dao.xml",
"applicationContext-service.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(cinfigs);
调配符参数方式:
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext*.xml");
Spring框架提供了多种自动装配方式
on:不使用自动装配。
byType:根据属性类型自动装配。
byName:根据属性名自动装配。
constructor:与byType的方式类似,不同之处在于,它应用于构造器参数。
Bean的作用域被划分为以下五种
singleton:默认值。
proptotype:每次从容器中获取Bean时,都会创建一个实例。
request:用于Web应用环境,针对每次HTTP请求都会创建一个实例。
Session:用于Web应用环境,同一个会话享同一个实例,不同的会话使用不同的实例。
global session:仅在Portlet的Web应用中使用,同一个全局会话共享一个实例。