spring源码分析 - wtdig/study GitHub Wiki
注释:报错No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency Possible solutions: values
解决方案:打开spring-beans\spring-beans.gradle 将下面的配置注释掉
//compileGroovy.dependsOn = compileGroovy.taskDependencies.values - ‘compileJava’
tomcat启动容器时,会读取web.xml文件,然后调用ServletContextListener接口的contextInitialized;
ContextLoaderListener实现了ServletContextListener接口,ServletContextListener是Java EE标准接口之一,类似tomcat,jetty的java容器启动时便会触发该接口的contextInitialized;
当web容器解析web.xml文件时,会初始化ContextLoaderListener类,这个类继承了ServletContextListener,也就是Web容器监听器。并且实现了ServletContextListener接口中的contextInitialized和contextDestroyed方法。
在spring Web中,需要初始化IOC容器,用于存放我们注入的各种对象。
当tomcat启动时首先会初始化一个web对应的IOC容器,用于初始化和注入各种我们在web运行过程中需要的对象。
当tomcat启动的时候是如何初始化IOC容器的,我们先看一下在web.xml中经常看到的配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
ContextLoaderListener是一个监听器,其实现了ServletContextListener接口,其用来监听Servlet,
当tomcat启动时会初始化一个Servlet容器,这样ContextLoaderListener会监听到Servlet的初始化,
这样在Servlet初始化之后我们就可以在ContextLoaderListener中也进行一些初始化操作。
看下面的ServletContextListener的源码也是比较简单的,ContextLoaderListener实现了ServletContextListener接口,
所以会有两个方法contextInitialized和contextDestroyed。
web容器初始化时会调用方法contextInitialized,web容器销毁时会调用方法contextDestroyed。
问题一:spring的循环依赖,依赖注入的三种方式(1、构造器;2、set方法(单例);3、set方法(多例)),目前spring无法解决构造器、set方式
(多例)的循环依赖问题,因为多例每次都会创建一个新的对象,无法使用提前加载的方法将bean存储起来,单例的话,现将bean存储起来,然
后再将依赖的对象注入进去,用到哪个bean,从提前存储的集合中取出来,这样就解决了循环依赖的问题。