spring初始化代码
DefaultListableBeanFactory.preInstantiateSingletons | 启动的beanfactory,创建bean |
AbstractAutowireCapableBeanFactory | 整个bean创建的过程 |
populateBean方法 | 根据property进行autowirebyName或byType注入,对xml配置的属性进行设置 |
initializeBean方法 | 初始化bean:下面是回调接口 |
BeanNameAware.setBeanName | |
BeanClassLoaderAwre.setBeanClassLoader | |
BeanFactoryAware.setBeanFactory | |
对BeanPostProcessor进行回调beanProcessor.postProcessBeforeInitialization | |
InitialzingBean.afterPropertiesSet | |
对initMethodName进行调用 | |
对BeanPostProcessor进行回调applyBeanPostProcessorsAfterInitialization |
spring bean lifecycle
Action | Description |
Initialization begins as bean is instantiated | The new bean is instantiated via a constructor, or by calling afactory method, which is considered equivalent. This happensas a result of a getBean() call on the factory, or thefact that another bean that was already being instantiatedhad a dependency on this one, triggering the creation of thisone first. |
Dependencies injected | Dependencies are injected into the instance, as previouslydiscussed. |
setBeanName() | called If the bean implements the optional interface, BeanNameAware, then that interface’s setBeanName() methodis called to provide the bean with its primary ID as declared inthe bean definition. |
setBeanFactory() | called If the bean implements the optional BeanFactoryAware interface, then that interface’s setBeanFactory() methodis called to provide the bean with a reference to the factory itis deployed in. Note that since application contexts are alsobean factories, this method will also be called for beansdeployed in an application context, however passing in thebean factory internally used by the context. |
setResourceLoader() | called If the bean implements the optional ResourceLoaderAware interface, and it is deployed in an application context,then that interface’s setResourceLoader() method iscalled, with the application context as the ResourceLoader.(To be discussed in the next chapter.) |
setApplicationEventPublisher | calledIf the bean implements the optionalApplicationEventPublisherAware interface, and it isdeployed in an application context, then that interface’s |
setApplicationEventPublisher() | method is called,with the application context as the ApplicationEventPublisher. (To be discussed in the next chapter.) |
setMessageSource() | called If the bean implements the optional MessageSourceAwareinterface, and it is deployed in an application context, thenthat interface’s setMessageSource() method is called,with the application context as the MessageSource. (To bediscussed in the next chapter.) |
setApplicationContext() | called If the bean implements the optional ApplicationContextAware() interface, and is deployed in an application context,then that interface’s setApplicationContext()method is called to provide the bean with a reference to thecontext. |
Bean post-processors get “beforeinitialization”callback with bean | Bean post-processors, which will be discussed shortly, arespecial handlers that applications may register with the factory.Post-processors get a pre-initialization callback with thebean, which they may manipulate as needed. |
afterPropertiesSet() | called If the bean implements the InitializingBean markerinterface, then afterPropertiesSet() from this interfaceis called to allow the bean to initialize itself. |
Declared init method called | If the bean definition defines an initialization method via theinit-method attribute, then this method is called to allowthe bean to initialize itself. |
Bean post-processors get “afterinitialization”callback with the beaninstance as argument | Any bean post-processors get a post-initialization callbackwith the bean instance, which they may manipulate asneeded, as an argument. |
Bean is used | The bean instance is actually used. That is, it’s returned tothe caller of getBean(), used to set a property on the otherbean that triggered its creation as a dependency, and so on.Important note: Only singleton beans are tracked past thispoint, with prototype beans being considered as owned bythe client using the bean. As such, the container will orchestrateonly the subsequent lifecycle events for singletonbeans. Any prototype beans have to be fully managed by theclient past this point, including calling any needed destroymethod. |
Bean destruction begins | As part of the bean factory or application context shutdownprocess, all cached singleton beans go through a destructionprocess, consisting of the actions following this one. Notethat beans are destroyed in appropriate order related to theirdependency relationship, generally the reverse of theinitialization order. |
Bean post-processors get “destroy”callback with bean | Any bean post-processors implementing theDestructionAwareBeanPostProcessors interface get acallback to manipulate the singleton bean for destruction. |
destroy() | called If a singleton bean implements the DisposableBean markerinterface, then that interface’s destroy() method is calledto allow the bean to do any needed resource cleanup. |
Declared destroy | method called If the bean definition of a singleton bean defines a destroymethod via the destroy-method attribute, then this methodis called to allow the bean to release any resources that needto be released.Initialization and Destruction CallbacksThe initialization |
spring的动态代理实现方法
DefaultListableBeanFactory.applyBeanPostProcessor | 创建类后回调BeanPostProcessor |
AnnotationAwareAspectJAutoProxyCreator.postProcessAfterInitialization | 回调 |
AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors | 查找advisors |
AnnotationAwareAspectJAutoProxyCreator.BeanFactoryAspectJAdvisorsBuilderAdapter.buildAspectJAdvisors | 查找全部初始化bean的Aspect是否存在advice,pointcut |
AnnotationAwareAspectJAutoProxyCreator.createProxy | 创建proxy(此处应该还有其他Processor) |
ProxyFactory.getProxy(ClassLoader) | 先通过ProxyFactory创建 |
DefaultAopProxyFactory.createAopProxy(AdviseSupport) | 创建proxy |
JdkDynamicAopProxy/CglibProxyFactory.createCglibProxy(config) | 选择jdk或cglib |
动态代理调用流程
JdkDynamicAopProxy.invoke | 调用代理方法 |
advised.getInterceptorsAndDynamicInterceptionAdvice | 获得拦截器或advice链表 |
new ReflectiveMethodInvocation().proceed | 创建调用对象并调用 |
Cglib2AopProxy.invoke | 调用代理方法 |
advised.getInterceptorsAndDynamicInterceptionAdvice | 获得拦截器或advice链表 |
new CglibMethodInvocation().proceed | 创建调用对象并调用 |
aop相关类
ProxyConfig | is the base class for all objects than can create AOP proxies. |
AdvisedSupport | holds configuration for objects with a single TargetSource and set of interfaces. |
ProxyFactoryBean | is used to define proxies in XML or other metadata configuration. As its name indicates, it is a FactoryBean, as discussed in Chapter 3 on Spring's IoC container. |
ProxyFactory | is used to create proxies programmatically, without an IoC container. |
AbstractAutoProxyCreator | and subclasses handle "autoproxying," discussed later. They inherit basic configuration from ProxyConfig, but do not extend from AdvisedSupport, as TargetSource, interfaces, andother AdvisedSupport configuration parameters are relevant to a single proxy type, rather than generic proxycreation. |
spring梳理依赖关系方法//TODO
DispatchServlet属性
Parameter | Description | Default Value |
contextClass | Type of WebApplicationContext to use | XmlWebApplicationContext |
namespace | The namespace of the WebApplicationContext to use | [name of servlet]-servlet |
contextConfigLocation | Parameter to override the default value of location(s) to look for WebApplicationContext(s) | /WEB-INF/[namespace].xml |
publishContext | Whether or not to publish to ApplicationContext in the ServletContext (making it available to other Servlets) | true |
spring mvc 如何实现参数自动映射
解决问题 | 实现类 | 思路 |
方法中String类型的形式参数映射 | LocalVariableTableParameterNameDiscoverer | 使用asm包的ClassReader |
spring mvc hander 拦截器
HandlerInterceptor
动态数据源,配置AbstractRoutingDataSource
public class DynamicDataSource extends AbstractRoutingDataSource { @Override protected Object determineCurrentLookupKey() { //String key = DataSourceContextHolder.getDataSourceKey(); return DataSourceContextHolder.getDataSourceKey(); } }
相关推荐
spring日志记录格式
利用Spring技术扩展统一记录系统操作日志
将spring2的开发包spring.jar替换为附件中压缩文件的所有jar包,既可以将spring2.0的应用升级到spring3.0.5
spring+hibernate整合实现简单数据库添加记录,适合初学spring的学员
Spring MVC 学习记录总结Spring MVC 是目前主流的实现MVC设计模式的框架,是Spring 框架的一个分支产品,以 Spring IoC 容器
4、想看spring aop 注解实现记录系统日志并入库等 二、能学到什么 1、收获可用源码 2、能够清楚的知道如何用spring aop实现自定义注解以及注解的逻辑实现 (需要知道原理的请看spring aop源码,此处不做赘述) 3、...
基于Vue和Spring Boot的校园记录管理Web App的设计与实现.pdf
参考记录: https://blog.csdn.net/u011488009/article/details/104002885 所有的SpringCloud能够实现三大模块: 服务发现——Netflix Eureka 客户端负载均衡——Netflix Ribbon 断路器——Netflix Hystrix ...
简单的demo4初学者,用到spring注解,log4j记录日志到文件
Spring.NET学习中的一点记录,没有用过spring.net的同学可以稍微参考下
全面的讲解了spring所有的知识!可以跟好的帮助你学习spring,里面有ioc aop di等一些切面编程思想!
校社联社团管理系统(Spring MVC+Spring+Mybatis+Redis),用来记录进度,和保存文件,完成一定阶段都上传到小组仓库中。 校社联社团管理系统(Spring MVC+Spring+Mybatis+Redis),用来记录进度,和保存文件,完成...
Spring Batch可以提供大量的,可重复的数据处理功能,包括日志记录/跟踪,事务管理,作业处理统计工作重新启动、跳过,和资源管理等重要功能。 业务方案: 1、批处理定期提交。 2、并行批处理:并行处理工作。 3、...
spring.net结合三层AOP异常日志记录功能
赠送jar包:spring-cloud-gateway-server-3.1.1.jar; 赠送原API文档:spring-cloud-gateway-server-3.1.1-javadoc.jar; 赠送源代码:spring-cloud-gateway-server-3.1.1-sources.jar; 赠送Maven依赖信息文件:...
SpringCloud+JDK17整合EaseExcel
Spring boot学习(六)Spring boot实现AOP记录操作日志.
aop日志记录。 4、调度 ====== Spring task, 可以查询已经注册的任务。立即执行一次任务。 5、缓存和Session =========== 注解redis缓存数据,Spring-session和redis实现分布式session同步(建议按功能模块...
ssb(struts2,spring3,mybatis3)实现的家庭费用记录系统,页面已经做好,思路是根据本人实际情况定制:总支出与总收入不计算信用卡、每月记录消费时需先记录本月原有金额等。 功能包括:本月当天支出于收入、本月总支...
自己学习Spring过程中做的记录 自己留着自己看