而ClassPathResource 对这个方法的实现就是通过类或者类加载器实现的
if (this.clazz != null) {
is = this.clazz.getResourceAsStream(this.path);
}
else if (this.classLoader != null) {
is = this.classLoader.getResourceAsStream(this.path);
}
获取了输入流那就自然可以获取文件的内容了。
2.Spring获取xml内容后通过XmlBeanDefinitionReader解析配置文件的内容封装成BeanDefinition方便后续使用。
/前边说了是XmlBeanFactory具体实现获取xml信息的功能
- public class XmlBeanFactory extends DefaultListableBeanFactory {
//xmlBeanFactory 中直接实例化 xmlBeanDefinitionReader
private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this);
…
public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
super(parentBeanFactory);
this.reader.loadBeanDefinitions(resource);
}
}
- public class XmlBeandefinitionReader extends AbstractBeanDefinitionReader{
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
…
try (
//获取输入流
InputStream inputStream = encodedResource.getResource().getInputStream()) {
//xml 解析工具类
InputSource inputSource = new InputSource(inputStream);
if (encodedResource.getEncoding() != null) {
inputSource.setEncoding(encodedResource.getEncoding());
}
//开始具体解析
return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
}
…
};
protected int doLoadBeanDefinitions(InputSource inputSource, Resource resource)
throws BeanDefinitionStoreException {
try {
// xml 解析为 document
Document doc = doLoadDocument(inputSource, resource);
// document 转 beanDefinition
int count = registerBeanDefinitions(doc, resource);
if (logger.isDebugEnabled()) {
logger.debug("Loaded " + count + " bean definitions from " + resource);
}
return count;
}
}
}
- public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocumentReader {
protected void doRegisterBeanDefinitions(Element root){
…
preProcessXml(root);
parseBeanDefinitions(root,this,dalegate);
postProcessXml(root);
};
protected void parseBeanDefinitions(Element root,BeanDefinitionParseDelegate delegate){
if (delegate.isDefaultNamespace(root)) {
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
if (delegate.isDefaultNamespace(ele)) {
//解析基本标签
parseDefaultElement(ele, delegate);
}
最后
即使是面试跳槽,那也是一个学习的过程。只有全面的复习,才能让我们更好的充实自己,武装自己,为自己的面试之路不再坎坷!今天就给大家分享一个Github上全面的Java面试题大全,就是这份面试大全助我拿下大厂Offer,月薪提至30K!
我也是第一时间分享出来给大家,希望可以帮助大家都能去往自己心仪的大厂!为金三银四做准备!
一共有20个知识点专题,分别是:
Dubbo面试专题
JVM面试专题
Java并发面试专题
Kafka面试专题
MongDB面试专题
MyBatis面试专题
MySQL面试专题
Netty面试专题
RabbitMQ面试专题
Redis面试专题
Spring Cloud面试专题
SpringBoot面试专题
zookeeper面试专题
常见面试算法题汇总专题
计算机网络基础专题
设计模式专题
[外链图片转存中…(img-XVjZLpRX-1714163943248)]
常见面试算法题汇总专题
[外链图片转存中…(img-o7D452c1-1714163943248)]
计算机网络基础专题
[外链图片转存中…(img-AIxpnL5G-1714163943248)]
设计模式专题
[外链图片转存中…(img-YX9LBC4O-1714163943249)]