随笔分类 -  Spring

1
摘要:文章目录 1. 利用```BeanPostProcessor```实现初始化2. 执行 ```@PostConstruct```注解3. 在```invokeInitMethods```方法中执行 各种初始化方法及执行顺序见《Bean 生命周期 钩子》。初始化bean在IOC初始化时的执行时机见《I 阅读全文
posted @ 2020-12-14 01:56 qianbuhan 阅读(154) 评论(0) 推荐(0)
摘要:文章目录 ```AbstractApplicationContext#finishBeanFactoryInitialization```——入口```doGetBean```——获取单个bean1. ```DefaultSingletonBeanRegistry#getSingleton```—— 阅读全文
posted @ 2020-12-14 01:38 qianbuhan 阅读(170) 评论(0) 推荐(0)
摘要:文章目录 ```AbstractApplicationContext#refresh```1. ```prepareRefresh```——刷新前预处理2. ```obtainFreshBeanFactory```——获取```beanFactory```3. ```prepareBeanFacto 阅读全文
posted @ 2020-12-06 11:28 qianbuhan 阅读(158) 评论(1) 推荐(0)
摘要:BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcessor。 BeanFactoryPostProcessor @FunctionalInterface public interface BeanFactoryPostProcesso 阅读全文
posted @ 2020-12-05 16:34 qianbuhan 阅读(200) 评论(0) 推荐(0)
摘要:TransactionInterceptor 执行事务方法时和 AOP 一样,会进入DynamicAdvisedInterceptor#intercept方法,拦截链中只有一个TransactionInterceptor拦截器。TransactionInterceptor继承了MethodInter 阅读全文
posted @ 2020-12-05 13:31 qianbuhan 阅读(179) 评论(0) 推荐(0)
摘要:@EnableTransactionManagement 可以看出这个注解的主要作用是导入TransactionManagementConfigurationSelector @Import(TransactionManagementConfigurationSelector.class) publ 阅读全文
posted @ 2020-12-05 13:01 qianbuhan 阅读(713) 评论(0) 推荐(0)
摘要:获取拦截链链式调用通知方法 一般情况下是DynamicAdvisedInterceptor里的intercept方法起作用。 DynamicAdvisedInterceptor是CglibAopProxy的内部类 DynamicAdvisedInterceptor#intercept public 阅读全文
posted @ 2020-12-04 10:54 qianbuhan 阅读(635) 评论(0) 推荐(0)
摘要:SmartInstantiationAwareBeanPostProcessor接口继承自InstantiationAwareBeanPostProcessor接口。 因此AbstractAutoProxyCreator一般是通过InstantiationAwareBeanPostProcessor 阅读全文
posted @ 2020-12-03 14:58 qianbuhan 阅读(864) 评论(0) 推荐(0)
摘要:implement PriorityOrderedimplement Orderedregister all regular BeanPostProcessorsre-register all internal BeanPostProcessors AbstractApplicationContex 阅读全文
posted @ 2020-12-03 11:06 qianbuhan 阅读(457) 评论(0) 推荐(0)
摘要:@EnableAspectJAutoProxy 可以看出这个注解的主要作用就是导入AspectJAutoProxyRegistrar @Import(AspectJAutoProxyRegistrar.class) public @interface EnableAspectJAutoProxy { 阅读全文
posted @ 2020-12-03 10:31 qianbuhan 阅读(316) 评论(0) 推荐(0)
摘要:赋值的类型: String @Value("spring")SpringEL @Value("#{20-10}")读取环境变量// 引入配置文件 @Configuration @PropertySource(value={"classpath:/value.properties"}) public 阅读全文
posted @ 2020-11-16 09:04 qianbuhan 阅读(323) 评论(0) 推荐(0)
摘要:BeanPostProcessor就是在执行初始化方法的前后进行一次后置处理。 // AbstractAutowireCapableBeanFactory protected Object initializeBean(String beanName, Object bean, @Nullable 阅读全文
posted @ 2020-11-16 08:48 qianbuhan 阅读(261) 评论(0) 推荐(0)
摘要:创建 ➡ 初始化 ➡ 销毁 创建 - 钩子 构造方法 初始化(属性赋值后进行初始化) - 钩子(按顺序) BeanPostProcessor接口的 postProcessBeforeInitialization@PostConstructInitializingBean接口的afterPropert 阅读全文
posted @ 2020-11-15 14:58 qianbuhan 阅读(52) 评论(0) 推荐(0)
摘要:Bean可以继承此接口。 getBean的时候,BeanName如果以 &开头,就直接返回此Bean 如果不是,就返回 getObject() public interface FactoryBean<T> { String OBJECT_TYPE_ATTRIBUTE = "factoryBeanO 阅读全文
posted @ 2020-11-15 14:29 qianbuhan 阅读(130) 评论(0) 推荐(0)
摘要:方式使用方法@Componet很多注解也标注了此注解,如 @Service等@Configuration配置类@Bean@ComponentScanvalue:指定要扫描的包 excludeFilters = Filter[](下面的@Filter) 指定扫描的时候按照什么规则排除那些组件 incl 阅读全文
posted @ 2020-11-15 10:56 qianbuhan 阅读(68) 评论(0) 推荐(0)
摘要:@Configuration public class BeanConfig { @Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public String testPrototypeBean() { System.out.println( 阅读全文
posted @ 2020-11-11 15:26 qianbuhan 阅读(86) 评论(0) 推荐(0)
摘要:多文件 # application.yml 文件中: # application-dev.yml 中的配置会覆盖 application.yml 的配置(有相同配置时) spring: profiles: active: dev # 也可以在运行时指定: java -jar xxx.jar --sp 阅读全文
posted @ 2020-11-04 12:42 qianbuhan 阅读(86) 评论(0) 推荐(0)
摘要:ApplicationContext @Configuration @Bean @ComponentScan @Scope @Lazy @Conditional @Component @Import 未完待续 <用法,流程> 阅读全文
posted @ 2020-09-30 13:09 qianbuhan 阅读(72) 评论(0) 推荐(0)
摘要:@EnableAspectJAutoProxy文件:@Import(AspectJAutoProxyRegistrar.class) 所以AspectJAutoProxyRegistrar起关键作用,看一下它的实现: // 继承了 ImportBeanDefinitionRegistrar 接口,该 阅读全文
posted @ 2019-11-07 15:00 qianbuhan 阅读(106) 评论(0) 推荐(0)
摘要:在配置类中使用 @EnableAspectJAutoProxy 才能使Aspect生效,在这篇文章中详细分析该注解的作用原理。 切面类使用 @Aspect 声明,同时需要@Component注册为组件(或用其他方式,Aspect不会自动注册为Spring组件) 切面类有以下主要功能(用法详见代码部分 阅读全文
posted @ 2019-11-07 11:13 qianbuhan 阅读(521) 评论(0) 推荐(0)

1