Spring--ClassPathXmlApplicationContext
public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { private Resource[] configResources; /** * Create a new ClassPathXmlApplicationContext for bean-style configuration. * @see #setConfigLocation * @see #setConfigLocations * @see #afterPropertiesSet() */ public ClassPathXmlApplicationContext() { } /** * Create a new ClassPathXmlApplicationContext for bean-style configuration. * @param parent the parent context * @see #setConfigLocation * @see #setConfigLocations * @see #afterPropertiesSet() */ public ClassPathXmlApplicationContext(ApplicationContext parent) { super(parent); } /** * Create a new ClassPathXmlApplicationContext, loading the definitions * from the given XML file and automatically refreshing the context. * @param configLocation resource location * @throws BeansException if context creation failed */ //下载一个定义好的xml,自动刷新上下文 public ClassPathXmlApplicationContext(String configLocation) throws BeansException { this(new String[] {configLocation}, true, null); } /** * Create a new ClassPathXmlApplicationContext, loading the definitions * from the given XML files and automatically refreshing the context. * @param configLocations array of resource locations * @throws BeansException if context creation failed */ //下载一个定义好的xml,自动刷新上下文 public ClassPathXmlApplicationContext(String... configLocations) throws BeansException { this(configLocations, true, null); } /** * Create a new ClassPathXmlApplicationContext with the given parent, * loading the definitions from the given XML files and automatically * refreshing the context. * @param configLocations array of resource locations * @param parent the parent context * @throws BeansException if context creation failed */ public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException { this(configLocations, true, parent); } /** * Create a new ClassPathXmlApplicationContext, loading the definitions * from the given XML files. * @param configLocations array of resource locations * @param refresh whether to automatically refresh the context, * loading all bean definitions and creating all singletons. * Alternatively, call refresh manually after further configuring the context. * @throws BeansException if context creation failed * @see #refresh() */ public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException { this(configLocations, refresh, null); } /** * Create a new ClassPathXmlApplicationContext with the given parent, * loading the definitions from the given XML files. * @param configLocations array of resource locations * @param refresh whether to automatically refresh the context, * loading all bean definitions and creating all singletons. * Alternatively, call refresh manually after further configuring the context. * @param parent the parent context * @throws BeansException if context creation failed * @see #refresh() */ public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException { super(parent); setConfigLocations(configLocations); if (refresh) { refresh(); } } /** * Create a new ClassPathXmlApplicationContext, loading the definitions * from the given XML file and automatically refreshing the context. * <p>This is a convenience method to load class path resources relative to a * given Class. For full flexibility, consider using a GenericApplicationContext * with an XmlBeanDefinitionReader and a ClassPathResource argument. * @param path relative (or absolute) path within the class path * @param clazz the class to load resources with (basis for the given paths) * @throws BeansException if context creation failed * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class) * @see org.springframework.context.support.GenericApplicationContext * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader */ public ClassPathXmlApplicationContext(String path, Class<?> clazz) throws BeansException { this(new String[] {path}, clazz); } /** * Create a new ClassPathXmlApplicationContext, loading the definitions * from the given XML files and automatically refreshing the context. * @param paths array of relative (or absolute) paths within the class path * @param clazz the class to load resources with (basis for the given paths) * @throws BeansException if context creation failed * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class) * @see org.springframework.context.support.GenericApplicationContext * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader */ public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz) throws BeansException { this(paths, clazz, null); } /** * Create a new ClassPathXmlApplicationContext with the given parent, * loading the definitions from the given XML files and automatically * refreshing the context. * @param paths array of relative (or absolute) paths within the class path * @param clazz the class to load resources with (basis for the given paths) * @param parent the parent context * @throws BeansException if context creation failed * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class) * @see org.springframework.context.support.GenericApplicationContext * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader */ public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, ApplicationContext parent) throws BeansException { super(parent); Assert.notNull(paths, "Path array must not be null"); Assert.notNull(clazz, "Class argument must not be null"); this.configResources = new Resource[paths.length]; for (int i = 0; i < paths.length; i++) { this.configResources[i] = new ClassPathResource(paths[i], clazz); } refresh(); } @Override protected Resource[] getConfigResources() { return this.configResources; } }
Spring--ClassPathXmlApplicationContext的更多相关文章
- Spring——ClassPathXmlApplicationContext(配置文件路径解析 1)
ClassPathXmlApplicationContext 在我的 BeanFactory 容器文章中主要提及了 BeanFactory 容器初始化(Spring 配置文件加载(还没解析)) ...
- [Spring] ClassPathXmlApplicationContext类
1. 该类在package org.springframework.context.support包下. 该包在4.0.1中封装在spring-context-***.jar中. 其无参构造函数的文档 ...
- Spring ClassPathXmlApplicationContext和FileSystemXmlApplicationContext读取配置文件的方法
先说:ClassPathXmlApplicationContext 这个类,默认获取的是WEB-INF/classes/下的路径,也就是在myeclipse的src下的路径,所以用这个是获取不到WEB ...
- Spring ClassPathXmlApplicationContext和FileSystemXmlApplicationContext
先说:ClassPathXmlApplicationContext 这个类,默认获取的是WEB-INF/classes/下的路径,也就是在myeclipse的src下的路径,所以用这个是获取不到WEB ...
- 尚学堂Spring视频教程(一):模拟Spring
Spring简单的说就是作为控制反转的容器,看这篇文章前需要先搞懂“控制反转和依赖注入“这个设计模式 我们先来模拟Spring,实现用户添加的功能,新建WEB项目”Spring_0100_Abstra ...
- Spring依赖注入 --- 模拟实现
Spring依赖注入 --- 模拟实现 面向接口编程,又称面向抽象编程, 数据库如果发生更改,对应的数据访问层也应该改变多写几个实现,需要用谁的时候在service里new谁就可以了面向抽象编程的好处 ...
- 使用JDom解析XML文档模拟Spring的配置文件解析
在J2EE项目中可能会涉及到一些框架的使用,最近接触到了SSH,拿Spring来说配置文件的使用是相当重要的,Spring的配置文件是一个xml文件,Spring是如何读取到配置文件并进行依赖注入的呢 ...
- spring IOC简单入门
spring的核心是ioc和aop 先介绍一下IOC(inverse of control控制反转)又叫DI(Dependency injection依赖注入) 个人理解为把对象的控制权由类转移到配置 ...
- 我也来写spring
本文可作为北京尚学堂 spring课程的学习笔记 我们还是用上一篇文章的例子 给数据库中增加一个user 整体代码如下 package com.bjsxt.test; import com.bjsxt ...
- 模拟Spring框架
BeanFactory package com.bjsxt.spring; public interface BeanFactory { public Object getBean(String na ...
随机推荐
- 合成/聚合复用原则(CARP)
组合/聚合复用原则(Composite/Aggregate Reuse Principle或CARP),就是在一个新的对象里面使用一些已有的对象,使之成为新对象的一部分,新对象通过向这些对象的委派达到 ...
- Spring之Core模块
Core模块主要的功能是实现了控制反转与依赖注入.Bean配置以及加载.Core模块中有Beans.BeanFactory.BeanDefinitions.ApplicationContext等概念 ...
- Makefile自动生成
automake/autoconf入门作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile ...
- Effective C++ ——资源管理
条款13:以对象来管理资源 在C++中我们经常会涉及到资源的申请与申请,一般都是由关键字new 和 delete来操作的,两者都是成对存在的,缺一不可,否则会出现意想不到的问题,例如: class I ...
- Dynamics CRM2015 页面导航栏顶部全局快速查找功能配置
在CRM2015中微软加入了新的快速查找功能,让你的数据查找更加方便,功能栏如下图所示,直接可以框中输入搜索项进行搜索. 但该功能是需要进行些配置,具体的配置在设置-管理-系统设置中,默认的就是红框中 ...
- 剑指Offer——全排列递归思路
剑指Offer--全排列递归思路 前言 全排列,full permutation, 可以利用二叉树的遍历实现.二叉树的递归遍历,前中后都简洁的难以置信,但是都有一个共同特点,那就是一个函数里包含两次自 ...
- Linux下使用gcc编程初体验
近期刚刚放弃了Windows,投入了Ubuntu 的怀抱.今天就拿一个小小的案例来做一下C语言的编译和运行流程.额,顺便说一句.本文适合那些Linux新手,不适合老鸟哈. 看完本文可以学到什么? 程序 ...
- DB2数据库常用命令
--创建数据库 CREATE DATABASE example AUTOMATIC STORAGE YES --自动存储 ON 'D:\' DBPATH ON'D:\' --指定数据库控制文件的存储路 ...
- Windows Server2008R2、2012R2重置系统开机登陆密码
平时用的虚拟机太多导致经常会忘记密码,这里分享两个链接,分别对应的是08R2和12R2重置密码的方法. 08R2:http://ucweb.blog.51cto.com/4042188/962284 ...
- Oracle EBS R12文件系统结构(学习汇总网上资料)
Oracle EBS R12在服务器端文件结构如下: 顶层目录下面分为 1)inst --–跟ebs整个实例(instance)相关的配置信息以及其他信息 2) db ---主要存储DB层的信息 ...