spring 怎么加载配置文件
展开全部
1.利用ClassPathXmlApplicationContext
可以从classpath中读取XML文件
(1)
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao userDao = (UserDao)context.getBean("userDao");
(2)
ClassPathXmlApplicationContext resource = new ClassPathXmlApplicationContext(new
String[]{"applicationContext-ibatis-oracle.xml","applicationContext.xml","applicationContext-data-oracle.xml"});
BeanFactory factory = resource; UserDao userDao = (UserDao)
factory.getBean("userDao");
2. 利用ClassPathResource
可以从classpath中读取XML文件
Resource cr = new ClassPathResource("applicationContext.xml");
BeanFactory bf=new XmlBeanFactory(cr); UserDao userDao =
(UserDao)bf.getBean("userDao");
可以从classpath中读取XML文件
(1)
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao userDao = (UserDao)context.getBean("userDao");
(2)
ClassPathXmlApplicationContext resource = new ClassPathXmlApplicationContext(new
String[]{"applicationContext-ibatis-oracle.xml","applicationContext.xml","applicationContext-data-oracle.xml"});
BeanFactory factory = resource; UserDao userDao = (UserDao)
factory.getBean("userDao");
2. 利用ClassPathResource
可以从classpath中读取XML文件
Resource cr = new ClassPathResource("applicationContext.xml");
BeanFactory bf=new XmlBeanFactory(cr); UserDao userDao =
(UserDao)bf.getBean("userDao");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询