Spring源码窥探之:xxxAware接口
Aware接口是一个标志性接口,继承此接口的接口xxxAware的实现类,在容器创建完成后,会回调实现方法,下面举例:
1. 有很多xxxAware接口,下面举两个例子
- /**
- * description: 将实现xxxAware接口的Bean注册到IOC容器中的时候,会将xxxAware的实现方法进行回调操作
- *
- * @author 70KG
- * @date 2018/12/17
- */
- @Component
- public class MyAware implements ApplicationContextAware, BeanNameAware {
- private ApplicationContext applicationContext;
- private String beanName;
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.applicationContext = applicationContext;
- Cat cat = (Cat) applicationContext.getBean("cat");
- System.out.println("------->" + cat);
- }
- @Override
- public void setBeanName(String name) {
- this.beanName = name;
- System.out.println("------->" + beanName);
- }
- }
2. 配置类
- /**
- * description
- *
- * @author 70KG
- * @date 2018/12/17
- */
- @Configuration
- public class MyConfig {
- @Bean
- public Cat cat() {
- return new Cat();
- }
- @Bean
- public Dog dog() {
- return new Dog();
- }
- @Bean
- public MyAware myAware() {
- return new MyAware();
- }
- }
3. 测试类
- /**
- * description
- *
- * @author 70KG
- * @date 2018/12/17
- */
- public class Test01 {
- public static void main(String[] args) {
- AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(MyConfig.class);
- Cat cat = (Cat) app.getBean("cat");
- System.out.println("------->" + cat);
- }
- }
4. 结果
- ------->myAware
- ------->com.nmys.story.springCore.springioc.importBean.Cat@78b66d36
- ------->com.nmys.story.springCore.springioc.importBean.Cat@78b66d36
Spring源码窥探之:xxxAware接口的更多相关文章
- Spring源码解析 - AbstractBeanFactory 实现接口与父类分析
我们先来看类图吧: 除了BeanFactory这一支的接口,AbstractBeanFactory主要实现了AliasRegistry和SingletonBeanRegistry接口. 这边主要提供了 ...
- spring源码系列(二):IOC接口设计分析
这里主要对springIOC接口体系进行简单的概述和分析,具体每个接口详细分析在下面目录: 参考内容: <Spring技术内幕:深入解析 Spring架构与设计原理> 和 <Spri ...
- 【spring源码分析】BeanDefinitionRegistryPostProcessor接口可自定义bean加入IOC
自定义BeanDefinitionRegistryPostProcessor BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcesso ...
- Spring源码窥探之:注解方式的AOP原理
AOP入口代码分析 通过注解的方式来实现AOP1. @EnableAspectJAutoProxy通过@Import注解向容器中注入了AspectJAutoProxyRegistrar这个类,而它在容 ...
- Spring源码窥探之:Spring AOP初步
AOP(Aspect Oriented Programming):即我们常说的面向切面编程. 什么是AOP?AOP是在我们原来写的代码的基础上,进行一定的包装,比如在方法执行前.方法返回后.方法抛出异 ...
- Spring源码窥探之:扩展原理BeanDefinitionRegistryPostProcessor
BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcessor,其中有两个接口,postProcessBeanDefinitionRegi ...
- Spring源码窥探之:声明式事务
1. 导入驱动,连接池,jdbc和AOP的依赖 <!-- c3p0数据库连接池 --> <dependency> <groupId>c3p0</groupId ...
- Spring源码窥探之:AOP注解
AOP也就是我们日常说的@面向切面编程,看概念比较晦涩难懂,难懂的是设计理念,以及这样设计的好处是什么.在Spring的AOP中,常用的几个注解如下:@Aspect,@Before,@After,@A ...
- Spring源码窥探之:@Profile
Spring为我们提供的多环境启动 1. 配置类,注入三个不同环境的数据源,并加上注解 /** * description: 以下准备了三套不同环境的数据源 * * @author 70KG * @d ...
随机推荐
- Saltack 针对用户进行权限控制
一. client_acl 配置使用 1.1 client_acl概述 开启对系统上非root的系统用户在master上执行特殊的模块,这些模块名可以使用正则表达式进行表示,不能指定对那些minion ...
- 8、2 es数据库的使用
1.注意问题.es和redis同时使用会报错 解决: package com.bw; import org.springframework.beans.factory.InitializingBean ...
- Hbase面试题
hbase的特点 )hbase适合存储海量数据,是一个分布式的,基于列式存储的数据库,基于hadoop的hdfs存储,zookeeper进行管理. )hbase 适合存储半结构化或非结构化的数据,对于 ...
- day41——数值类型、完整性约束
day41 数值类型 整数类型 有符号的设置 mysql> create table t1(id tinyint); # 默认有符号,即数字前有正负号 无符号的设置 mysql> crea ...
- php策略模式实现简单计算器
html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- nginx 简单介绍
Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Uniform Resources Identifier)URI或者统一资源定位符(Uniform Resou ...
- 物流管理系统(SSM+vue+shiro)【前后台】
一.简单介绍项目 该项目是属于毕业设计项目之一,有前台的用户下单.有司机进行接单.有管理员进行操作后台,直接进入主题 毕设.定制开发 联系QQ:761273133 登录主页: 手机号码+验证码登录 或 ...
- springboot 2.1.3.RELEASE添加filter,servlet源码学习
Servlet规范中,通过ServeltContext来注册Filter.Servlet,这里分析Filter,Servlet是相同逻辑 springboot2.0中,我们通过 FilterRegis ...
- 关于Java无法解码(ajax编码 Java解码)
今天遇到了一个非常奇~~~~~~葩的问题,无解! 一向前端碰到中文,请求都使用encodeURI(encodeURI("中文"))编码,然后后端使用URLDecoder.decod ...
- Dubbo的10种集群容错模式
学习Dubbo源码的过程中,首先看到的是dubbo的集群容错模式,以下简单介绍10种集群容错模式 1.AvailableCluster 顾名思义,就是可用性优先,遍历所有的invokers,选择可用的 ...