spring
文章平均质量分 52
spring
麦田里的稻草人19994
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Spring容器的refresh() 过程三、核心bean创建流程
initApplicationEventMulticaster方法在spring 事件监听器原理分析 的时候有分析过,可以参考下,下面主要分析finishBeanFactoryInitialization方法@Override public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this con.原创 2020-09-14 01:00:50 · 348 阅读 · 0 评论 -
Spring容器的refresh() 过程 二、
@Override public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this context for refreshing. prepareRefresh(); // Tell the subclass to refresh the internal bean factory.原创 2020-09-13 17:04:30 · 262 阅读 · 0 评论 -
Spring容器的refresh() 过程 一、BeanFactory的创建及预准备工作
准备源码调试环境准备调试环境,当前的spring源码为 spring-framework-4.3.12.RELEASEmaven环境<!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spri原创 2020-09-13 00:29:02 · 338 阅读 · 0 评论 -
spring 事件监听器原理分析
先搭建源码分析环境,这里引用的是org.springframework4.3.12.RELEASE版本分析的,debug之前github上下载相关源码-地址 除了在上述代码中打上断点之外,增加EventListenerMethodProcessor的afterSingletonsInstantiated方法打上断点,AbstractApplicationContext的initApplicationEventMulticaster方法和registerListeners上打上断点。@Componen.原创 2020-09-02 23:32:09 · 653 阅读 · 0 评论 -
spring BeanDefinitionRegistryPostProcessor 原理分析
在所有bean定义信息将要被加载,bean实例还未创建时,优先于BeanFactoryPostProcessor执行,利用BeanDefinitionRegistryPostProcessor给容器中再额外添加一些组件。源码测试环境搭建@ComponentScan("com.atguigu.ext")@Configurationpublic class ExtConfig { @Bean public Blue blue(){ return new Blue(); }}@Co.原创 2020-09-02 00:23:32 · 190 阅读 · 0 评论 -
spring BeanFactoryPostProcessor原理分析
BeanFactoryPostProcessor是beanFactory的后置处理器,在BeanFactory标准初始化之后调用,来定制和修改BeanFactory的内容,所有的bean定义已经保存加载到beanFactory,但是bean的实例还未创建。先搭建源码分析环境@ComponentScan("com.atguigu.ext")@Configurationpublic class ExtConfig { @Bean public Blue blue(){ return new.原创 2020-09-02 00:00:33 · 168 阅读 · 0 评论 -
spring 声明式事务源码分析
同理,先搭建源码分析调试环境@Repositorypublic class UserDao { @Autowired private JdbcTemplate jdbcTemplate; public void insert(){ String sql = "INSERT INTO `tbl_user`(username,age) VALUES(?,?)"; String username = UUID.randomUUID().toString().substring(0, 5).原创 2020-09-01 16:10:52 · 200 阅读 · 0 评论 -
三、spring aop 原理之 目标方法执行
调试代码搭建参考断点为LogAspects类与MathCalculator每个方法 debug执行方法进入断点,intercept方法@Overridepublic Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; boolean setProxyContext = fal.原创 2020-08-31 17:00:16 · 519 阅读 · 0 评论 -
二、spring aop 原理之 创建代理对象
源码分析之前,先搭建源码分析环境这里引用的是org.springframework4.3.12.RELEASE版本分析的,debug之前github上下载相关源码–地址 打断点的位置如下标注,同时,为了查看AbstractAutoProxyCreator代理对象创建器的处理逻辑,在其postProcessBeforeInstantiation与postProcessAfterInitialization方法处打上断点。@EnableAspectJAutoProxy@Configurationpu.原创 2020-08-31 00:03:27 · 258 阅读 · 0 评论 -
一、spring aop 原理之 后置处理器 AnnotationAwareAspectJAutoProxyCreator 源码解析
1.向容器中注册AnnotationAwareAspectJAutoProxyCreator当开启基于注解的aop模式,要添加注解 @EnableAspectJAutoProxy,点进@EnableAspectJAutoProxy的源码此注解帮助spring处理标记了 AspectJ注解的组件,有点类似原来的xml配置文件里面的 aop:aspectj-autoproxy/** * Enables support for handling components marked with Asp原创 2020-08-29 20:59:30 · 450 阅读 · 0 评论 -
spring aware 接口源码浅析
先来看下aware的官方注释Marker superinterface indicating that a bean is eligible to benotified by the Spring container of a particular framework objectthrough a callback-style method. Actual method signature isdetermined by individual subinterfaces, but should原创 2020-08-23 14:56:41 · 241 阅读 · 0 评论 -
spring自动装配-@Autowired、@Qualifier、@Primary、@Resource、@Inject组合使用
Spring利用依赖注入(DI),完成对IOC容器中中各个组件的依赖关系赋值;常用的有如下几个注解@Autowired,@Qualifier、@Primary、@Resource、@Inject,组合使用,完成对bean 的依赖注入注解名称说明注意点@Autowired默认优先按照类型去容器中找对应的组件,找到就赋值,如果找到多个相同类型的组件,再将属性的名称作为组件的id去容器中查找,可以使用@Autowired(required=false)@Qualifier.原创 2020-08-19 18:58:11 · 475 阅读 · 0 评论 -
spring属性赋值-@value赋值与@PropertySource加载外部配置文件
1.@Value 赋值1、基本数值2、可以写SpEL表达式:#{ }3、可以写${ },取出配置文件中的值2. @PropertySource读取外部配置文件中的k/v保存到运行的环境变量中;加载完外部的配置文件以后使用${}取出配置文件的值案例:public class Person { @Value("张三") private String name ; @Value("${person.nickName}") private String ni原创 2020-08-19 13:10:44 · 471 阅读 · 0 评论 -
spring生命周期-BeanPostProcessor在spring中应用
BeanPostProcessor 接口在spring中的实现类比较多,挑选几个比较重要的了解下1.ApplicationContextAwareProcessor可以通过实现ApplicationContextAware 接口,给bean里面注入applicationContext ;@Componentpublic class Dog implements ApplicationContextAware { private ApplicationContext applicationCo原创 2020-08-19 00:28:37 · 242 阅读 · 0 评论 -
spring生命周期-BeanPostProcessor使用与原理浅析
额外原创 2020-08-18 23:19:30 · 321 阅读 · 0 评论 -
spring 生命周期-bean的初始化和销毁方法
bean的创建—初始化----销毁的过程中 ,容器管理bean的生命周期; 我们可以自定义初始化和销毁方法;容器在bean进行到当前生命周期的时候来调用我们自定义的初始化和销毁方法。下面简单介绍下面三种方式来自定义我们的bean的初始化和销毁方法1.通过@Bean指定init-method和destroy-method2.通过让Bean实现InitializingBean(定义初始化逻辑),DisposableBean(定义销毁逻辑)3.使用JSR250 @PostConstruct:在bean创建原创 2020-08-18 17:25:51 · 328 阅读 · 0 评论 -
spring bean容器注册之FactoryBean
1.首先看下接口注释说明public interface FactoryBean<T> { /**返回对象的实例 */ T getObject() throws Exception; /** 获取对象的类型 */ Class<?> getObjectType(); /** true是单例,false是多例 */ boolean isSingleton();}2.实例package com.atguigu.bean;import原创 2020-08-17 23:35:45 · 180 阅读 · 0 评论 -
spring常用注解@Import
1.先来看下原创 2020-08-10 23:27:41 · 279 阅读 · 0 评论 -
spring常用注解@Conditional
1.先全局搜下spring官方文档,找到了关于@Conditional的部分信息这个解释的简单概况呢,就是@Profile的注解,是通过@Condition实现的再点进这个官方关于@Condition的官方文档简单总结下:1.只有满足特定条件(自己实现相关方法),被此注解注解的部分才能生效2.特定条件为实现Condition接口与match方法,返回true注册,false不注册3.此注解的应用场景1.和@Component@Configuration组合使用在类上,和@Bean组合用在方原创 2020-08-07 00:17:30 · 252 阅读 · 0 评论
分享