Resource(Spring里<br>统一把所有资源抽象)<br>
上层类InputStreamSource
getInputStream获取到文件流就可以进行各种操作了
方法
exists
isFile
isOpen<br>
isReadable
getFile
getURI
子类1 :ClassPathResource ,<br>就是用来加载classPath路径下的资源的<br>
this.clazz.getResourceAsStream(this.path)<br>
子类2:FileSystemResource,
Files.newInputStream():根据文件路径去加载<br>
子类3:UrlResource
this.url.openConnection().getInputStream()<br>
ByteArrayResource<br>
new ByteArrayResource(this.bytes)<br>
ClassPathResource读取配置文件,解析bean标签,<br>通过class属性找到bean的全局类名,反射创建bean,<br>再将bean放入到spring容器里,以Id作为key,当我们调用getBean方法时,<br>就从容器里读取,返回bean实例<br>
XmlBeanDefinitionReader.loadBeanDefinitions(resource)<br>
Spring中每个bean的属性,方法,<br>构造方法信息都会封装到BeanDefinition中,注册到容器中就是以这个数据结构<br>
根据编码和字符集准备好资源,为下一步加载bean做准备<br>
doLoadDocument,根据输入流创建xml文件对应的document<br>
DocumentBuilderFactory-》DocumentBuilder->parse0>Document<br>
EntityResolver 校验XML方式:DTD XSD <br>
BeansDtdResolver找spring-beans.dtd<br>
PluggableSchemaResolver 加载META-INF/spring.schemas<br>
通过applicationContext.xml是否含有DOCTYPE字符串判断使用哪种解析器<br>
registerBeanDefinitions,解析document,并注册bean到spring中去<br>
解析Spring标签BeanDefinitionParserDelegate.parseDefaultElement<br>
初步解析bean,id,name、class标签<br>
放到GenericBeanDefinition<br>
Aware感知接口
一个bean实现了感知接口,spring容器在实例化bean的时候就会调用感知接口的方法,<br>将容器内部的对象注入到感知接口方法中,这些bean就可以拿到spring内部的对象,就可以做自定义功能改造<br>
BeanNameAware<br>
BeanFactoryAware<br>
BeanClassLoaderAware