spring
文章平均质量分 71
包括spring源码分析、spring高级用法、spring常用用法等方面
敲代码的小小酥
上天,请赐予我平静,去接受我无法改变的;给予我勇气,去改变我能改变的;赐我智慧,分辨两者的区别
展开
-
对Spring AOP的进一步深入理解
spring aop理解原创 2022-09-19 16:33:13 · 317 阅读 · 0 评论 -
Spring之bean标签属性详解
id:bean在spring容器的唯一标识,spring容器中不可能同时存在两个相同的id。class:类的全限定名(类名+包名),用“.”号连接name:设置别名,在BeanFactory的getBean(“name”)中可以获取相应的bean。需要注意的是,bean属性的id和name,是bean的唯一标识,同一个spring的配置文件中,不同bean的id和name是不能相同的。否则会报错。不同的spring配置文件中,id和name可以重复。此时spring针对相同的id或name采取的原创 2021-07-14 17:07:31 · 5213 阅读 · 0 评论 -
Spring之BeanDefinition详解
前言Spring在初始化过程中,将xml中定义的对象解析到了BeanDefinition对象中,我们有必要了解一下BeanDefinition的内部结构,有助于我们理解Spring的初始化流程。一、BeanDefinition接口下面我们翻译其注释。A BeanDefinition describes a bean instance, which has property values, constructor argument values, and further information su原创 2021-07-13 15:41:59 · 1418 阅读 · 2 评论 -
Spring之BeanFactory详解
前言顾名思义,BeanFactory是生产Bean的工厂。Bean就是Spring容器管理的对象。下面我们分析一下BeanFactory及其子类的源码,对我们深入理解Spring的初始化和原理非常有帮助一、BeanFactory分析/* * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you ma原创 2021-07-13 13:27:25 · 1956 阅读 · 1 评论 -
Spring之@Bean注解详解
@Bean总体介绍此注释的属性的名称和语义有意地与springxml模式中的元素的名称和语义相似。Spring的@Bean注解用于告诉方法,产生一个Bean对象,然后这个Bean对象交给Spring管理。产生这个Bean对象的方法Spring只会调用一次,随后这个Spring将会将这个Bean对象放在自己的IOC容器中。SpringIOC 容器管理一个或者多个bean,这些bean都需要在@Configuration注解下进行创建,在一个方法上使用@Bean注解就表明这个方法需要交给Spring进行管原创 2021-07-25 17:43:16 · 3442 阅读 · 0 评论 -
@Autowired注解详解
一、在构造函数上定义关于在构造方法上加@Autowired注解,讲下面几点:1.带有@Autowired注解(属性required默认为true)的构造方法,在Spring初始化对象实例时,会调用此构造函数,进行对象的实例化。2.如果构造方法上带有了@Autowired注解,那么这个构造方法不是public修饰的,也可以被实例化。private修饰的,也可以被实例化出来。3.当一个对象只有一个构造方法时,Spring实例化对象会默认选择这个构造方法进行实例化,无需加@Autowired注解。只有当多原创 2021-08-01 10:35:30 · 27809 阅读 · 0 评论 -
Spring之FactoryBean详解
前言Spring中有BeanFactory接口,也有FactoryBean接口。注意不要混淆两者。有关BeanFactory的内容,请查看博主的另一篇文章:《Spring之BeanFactory详解》FactoryBean源码解析首先,先看其类的结构图:该接口定义的方法不算多,可以看到定义了一个getObject方法,获取对象。getObjectType方法,获取对象类型,还有一个判断是否单利的方法。那么是获取什么对象,判断什么对象是单利呢?我们看其详细注解。1.如果一个bean实现了这个接口,原创 2021-08-30 11:18:25 · 4539 阅读 · 1 评论 -
Spring之BeanDefinitionRegistryPostProcessor类详解
一、BeanDefinitionRegistryPostProcessor类/* * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a c原创 2021-07-18 19:13:48 · 3785 阅读 · 0 评论 -
Spring注解PropertySource
@PropertySource和@PropertySources注解映射properties配置文件的属性到java类中。参考文章:使用@PropertySource加载配置文件原创 2021-08-30 14:49:05 · 90 阅读 · 0 评论 -
Spring之PropertyResourceConfigurer及其子类详解
一、PropertyResourceConfigurer类/* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of th原创 2021-10-09 09:28:14 · 388 阅读 · 0 评论 -
Spring之Environment类详解
一、Environment接口先上源码:package org.springframework.core.env;/** * Interface representing the environment in which the current application is running. * Models two key aspects of the application environment: <em>profiles</em> and * <em>原创 2021-08-15 11:36:05 · 2865 阅读 · 0 评论 -
Spring之循环依赖
一、什么是循环依赖简单来说,就是A类中,有B类的成员属性;同时,在B类中,有A类的成员属性。且成员属性要通过IOC进行赋值。最常见的应用就是,我们在Service层进行依赖时,很多情况是一个service依赖着另一个service,而另一个service也依赖着这个service。这就是典型的循环依赖。二、开启关闭循环依赖Spring提供了循环依赖的开关。AbstractAutowireCapableBeanFactory类中提供了setAllowCircularReferences()方法。默认值原创 2021-08-08 22:17:07 · 372 阅读 · 0 评论 -
Spring循环依赖之一、二、三级缓存
找到一位大佬的博客,直接拜读这篇文章即可Spring 解决循环依赖为什么使用三级缓存,而不是二级缓存这里做个总结:1.这里所说的一级、二级、三级缓存,只是在循环依赖中才会用到。如果没有循环依赖逻辑,不会用到这三个缓存。2.一级缓存存放实例化完成,且属性填充后的对象。二级缓存存放对象实例化完成后,还没有填充完属性值的对象。三级缓存存放的是工厂对象。存放实例化对象所需要的工厂。...原创 2021-08-08 19:41:25 · 1254 阅读 · 0 评论 -
Spring之AOP基础知识
1.基本概念切面(Aspect)带有advisor英文的都是切面:要增强的功能,都是切面,比如日志,事务,缓存等功能。代理:内存中动态形成的对象增强:具体的增强代码切点: 连接点的集合连接点:一个连接点对应一个被代理方法2.切面Advisor的两个重要元素:切点pointcut和增强AdvicePointcut来判断哪些类需要生成代理对象,进行增强。Adivce就是要增强的方法。PonitCut中,通过ClassFilter拦截要代理的类,通过MethodMatcher拦截要增强的方法。拦原创 2021-09-10 07:00:50 · 304 阅读 · 0 评论 -
Spring AOP之PointCut详解
一、PointCut接口/* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *原创 2021-09-02 17:04:49 · 2528 阅读 · 1 评论 -
Spring之Joinpoint类详解
说明Jointpoint是AOP的连接点。我们从源码角度看连接点有哪些属性和功能。源码/* * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obt原创 2021-09-09 15:19:52 · 16588 阅读 · 0 评论 -
Spring之@EnableAspectJAutoProxy开启AOP功能原理
疑问在使用AOP功能时,我们需要用@EnableAspectJAutoProxy手动开启AOP功能,否则不生效,为什么写了@EnableAspectJAutoProxy注解就可以使用AOP功能了呢,其中的原理是什么呢?答案在Spring中,无论是AOP功能还是其他需要手动开启的功能,实现思路大致如下:开启功能的注解中,@Import了一个类,这个类都是BeanDefinitionPostprocessor类型的对象,在这个对象中,把开启相关功能的入口类,加入到了Spring容器中,所以就具有了该功能原创 2021-10-12 13:57:30 · 981 阅读 · 0 评论 -
Spring之事件机制详解
机制详解Spring提供了事件机制,其本质是JDK提供的事件机制的应用,利用的是观察者设计模式,具体请看设计模式之观察者模式(Observer Pattern)。这里我们来分析Spring事件机制的原理。先上UML图,不熟悉UML规则的可以看UML类图的制作规则。下面我们对上图中涉及到的几个类进行讲解。ApplicationEvent:抽象类,继承了JDK的EventObject接口,起到包装事件源的作用。ApplicationListener:实现了JDK的EventListener接口原创 2021-07-24 12:22:22 · 909 阅读 · 2 评论 -
Spring之Cache缓存详解
前言Spring的Cache缓存类似于java的JDBC。是定义了一套规范。第三方缓存需要实现这套规范,才能通过Spring API使用缓存功能。这套规范的核心接口是CacheManager和Cache。其中,CacheMananger是获取Cache的入口。Cache是实现缓存逻辑的接口。下面具体看这两个接口。CacheManager我们先看其源码:public interface CacheManager { /** * Get the cache associated with th原创 2021-09-19 18:25:21 · 5442 阅读 · 0 评论