一头扎进Spring源码之ContextLoader

    xiaoxiao2021-03-25  118

    列出以供参考:

    类的初始化顺序: 父类静态代码块,实例变量  >  子类静态代码块,实例变量 > 父类非静态代码块,实例变量 > 子类非静态代码块,实例变量

    > 父类构造方法 > 子类构造方法

    即静态  优先于 非静态 其次 构造方法, 父类 优先于 子类

    包org.springframework.web 层级结构如下:

    回顾总结:

    ContextLoaderListener  的初始化依赖于其父类ContextLoader 和参数ServletContextEvent,  而ServletContextEvent 获取的是ServletContext的对象源,这个源是通过其父类EventObject提供的构造方法和getSource()方法获取到初始化和获取实例对象的。实例化的ServletContext对象的各项属性是在Java Web 容器里通过读取配置文件获取到的,其中就包括contextConfigLocation,load-on-startup等属性。

    我们一直在讲容器、容器、容器,Java Web 容器,Spring 容器等等,到底容器是个什么东西呢?

    Java Web 的容器是什么?Java Web 容器就是Servlet 容器。那么Servlet 容器是什么呢? 在我们这里讲,就是Tomcat这个服务器,运行起来的Tomcat, 就是一个Servlet 容器。那它的配置文件呢?web.xml。是的,可不要小看这个不起眼儿的“小东西”。

    书接上回

    我们再扯回到这个ContextLoaderListener和它的父类ContextLoader如上图,我在截图的右侧给出了ContextLoader类的这段静态代码块

    static { try { /* * ContextLoader.properties 只有下边这一对键值对: * org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext */ ClassPathResource ex = new ClassPathResource("ContextLoader.properties", ContextLoader.class); defaultStrategies = PropertiesLoaderUtils.loadProperties(ex); } catch (IOException var1) { throw new IllegalStateException("Could not load \'ContextLoader.properties\': " + var1.getMessage()); } currentContextPerThread = new ConcurrentHashMap(1); } 先不写了,  有空再添改

    转载请注明原文地址: https://ju.6miu.com/read-7571.html

    最新回复(0)