《Spring 框架高级编程》学习笔记

1、普通加载

ApplicationContext appContext = new 
        ClassPathXmlApplicationContext("ch03/sample2/applicationContext.xml");
BeanFactory factory = (BeanFactory)appContext; 
 
ApplicationContext appContext = new 
        FileSystemXmlApplicationContext("/some/file/path/applicationContext.xml");
BeanFactory factory = (BeanFactory)appContext;

 

2、多个文件加载

ApplicationContext appContext = new ClassPathXmlApplicationContext (
        new String[] {"applicationContext-services.xml", "applicationContext-dao.xml"}
);

 3、classpath*加载

ApplicationContext appContext = new ClassPathXmlApplicationContext("classpath*:ApplicationContext.xml");

 4、Resource方式

ClassPathResource res = new ClassPathResource("org/springframework/prospering/beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);
 
FilesystemResource res = new FilesystemResource("/some/file/path/beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);

 5、InputStream加载

InputStream is = new FileInputStream("/some/file/path/beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(is);

 6、分离方式

ClassPathResource res = new ClassPathResource("beans.xml");
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(res);

你可能感兴趣的:(DAO,spring,编程,框架,xml)