spring
文章平均质量分 73
第二人间
当我知道的越多,越知道自己一无所知
展开
-
Spring动态代理选择逻辑代码是如何实现的
Spring的动态代理支持cglib和jdk两种代理模式。对于两种动态代理的选择我们通常会说,当一个类实现了接口,Spring会使用jdk代理模式,否则使用cglib的代理模式。因为jdk代理要求一个类必须实现接口,而cglib代理可以将目标类当做父类来实现代理逻辑。但Spring具体在代码层级上是如何实现选择逻辑的呢?我们来看一下,先看一个类public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {原创 2020-08-05 23:41:46 · 432 阅读 · 0 评论 -
梳理Spring获取Bean的流程
Spring获取Bean的方法在接口BeanFactory中定义public interface BeanFactory { Object getBean(String name) throws BeansException; <T> T getBean(String name, Class<T> requiredType) throws BeansException; Object getBean(String name, Object... args) thro原创 2020-08-03 18:34:00 · 551 阅读 · 0 评论 -
剖析Spring AOP的全貌
版本说明:Spring Boot 2.2.8.RELEASE,Spring 5.2.7.RELEASE我们首先来看一下,我们如何实现自定义的切面逻辑第一步,引入aop依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId></dependency>原创 2020-07-19 14:44:51 · 57 阅读 · 0 评论 -
SpringBoot项目中默认动态代理是jdk proxy还是cglib
在SpringBoot项目中,当我们想使用Spring AOP的功能,我们首先要做的是引入aop的依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId></dependency>我们无需自定义aop相关的配置类,因为在autoconfigure包中已经原创 2020-07-18 23:49:14 · 3327 阅读 · 3 评论 -
@ImportSelector示例
如果你看Spring的源码,对@ImportSelector注解一定不陌生。原本想写一篇原理性的文章,但研究了一天发现还是不能完全理顺。于是,先尝试编写了一个示例,也不知道这样用正不正确……@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Import(TestImportSelector.class)public @interface TestImport { boolean test()原创 2020-07-12 20:30:25 · 661 阅读 · 0 评论 -
BeanFactoryAware BeanPostProcessor InitializingBean
这三个接口,你在你的项目里大概都实现过,但你有了解过这三个接口的执行顺序吗?我们先看一下这三个接口的接口方法public interface BeanFactoryAware extends Aware { void setBeanFactory(BeanFactory beanFactory) throws BeansException;}public interface BeanPostProcessor { @Nullable default Object postProcess原创 2020-06-18 20:31:48 · 152 阅读 · 0 评论 -
RedisTemplate executePipelined 第二个参数
使用管道的方式存储数据时,会直接保存字节数组,不需要用到序列化的功能redisTemplate.executePipelined(new RedisCallback<Object>() { @Override public Object doInRedis(RedisConnection connection) { keys.forEach(key...原创 2019-12-25 11:42:22 · 3638 阅读 · 0 评论