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接口的更多相关文章

  1. Spring源码解析 - AbstractBeanFactory 实现接口与父类分析

    我们先来看类图吧: 除了BeanFactory这一支的接口,AbstractBeanFactory主要实现了AliasRegistry和SingletonBeanRegistry接口. 这边主要提供了 ...

  2. spring源码系列(二):IOC接口设计分析

    这里主要对springIOC接口体系进行简单的概述和分析,具体每个接口详细分析在下面目录: 参考内容: <Spring技术内幕:深入解析 Spring架构与设计原理> 和 <Spri ...

  3. 【spring源码分析】BeanDefinitionRegistryPostProcessor接口可自定义bean加入IOC

    自定义BeanDefinitionRegistryPostProcessor BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcesso ...

  4. Spring源码窥探之:注解方式的AOP原理

    AOP入口代码分析 通过注解的方式来实现AOP1. @EnableAspectJAutoProxy通过@Import注解向容器中注入了AspectJAutoProxyRegistrar这个类,而它在容 ...

  5. Spring源码窥探之:Spring AOP初步

    AOP(Aspect Oriented Programming):即我们常说的面向切面编程. 什么是AOP?AOP是在我们原来写的代码的基础上,进行一定的包装,比如在方法执行前.方法返回后.方法抛出异 ...

  6. Spring源码窥探之:扩展原理BeanDefinitionRegistryPostProcessor

    BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcessor,其中有两个接口,postProcessBeanDefinitionRegi ...

  7. Spring源码窥探之:声明式事务

    1. 导入驱动,连接池,jdbc和AOP的依赖 <!-- c3p0数据库连接池 --> <dependency> <groupId>c3p0</groupId ...

  8. Spring源码窥探之:AOP注解

    AOP也就是我们日常说的@面向切面编程,看概念比较晦涩难懂,难懂的是设计理念,以及这样设计的好处是什么.在Spring的AOP中,常用的几个注解如下:@Aspect,@Before,@After,@A ...

  9. Spring源码窥探之:@Profile

    Spring为我们提供的多环境启动 1. 配置类,注入三个不同环境的数据源,并加上注解 /** * description: 以下准备了三套不同环境的数据源 * * @author 70KG * @d ...

随机推荐

  1. Windows 反弹 Shell

    NC 反弹 shell 攻击场景: Victim IP: 192.168.2.10 Attacker IP:192.168.2.11 正向 Shell 我们想要弹回Victim的Shell,使用如下命 ...

  2. [转帖]helm模板文件chart编写语法详解

    helm模板文件chart编写语法详解 https://blog.51cto.com/qujunorz/2421328 需要学习一下. charts编写介绍 开始 快速创建一个chart模板,helm ...

  3. 删除List集合中的元素你碰到过这样的陷阱吗?

    删除List的三种方式: (1) 普通遍历 : @Test public void testList(){ ArrayList<String> list = new ArrayList&l ...

  4. My Swift Study

    参考资源 <swifter> https://github.com/iOS-Swift-Developers/Swift 闭包逃逸 swift3中,闭包默认是非逃逸的.如果一个函数参数可能 ...

  5. AS3.0 m3u8文件视频播放器

    AS3.0 m3u8文件视频播放器(暂无源码): 点击欣赏! http://lxmc.aomaya.com/fengzi/m3u8/m3u8Player.swf

  6. [LOJ2292] [THUSC2016] 成绩单

    题目链接 LOJ:https://loj.ac/problem/2292 洛谷:https://www.luogu.org/problemnew/show/P5336 Solution 区间\(\rm ...

  7. 斐波那契数列(递归)c#

    我郑重宣布 我爱递归 我自己编程几乎都没用过递归 我看到这个题的时候虽然想到了用递归 但是我个脑残一直在想怎么设置动态数组 明明纯递归更简单 我也是可无语 反正我爱上递归了 爱惹  无法自拔

  8. python-django框架中使用docker和elasticsearch配合实现搜索功能

    注意:系统环境为Ubuntu18 一.docker安装 0:如果之前有安装过docker使用以下命令卸载: sudo apt-get remove docker docker-engine docke ...

  9. Synchronized 和 Lock 的主要区别(转)

    Synchronized 和 Lock 的主要区别Synchronzied 和 Lock 的主要区别如下: 存在层面:Syncronized 是Java 中的一个关键字,存在于 JVM 层面,Lock ...

  10. javasript简单实现文字的展开收起(无动画)

    今天在工作遇到展开和收起的需求,在网上找了很多方法,今天来写一下我觉得比较简单的方法 在项目中需要达到如图这种效果 首先想的是使用overflow简单且粗暴,在需要展开的的文字定义样式 { overf ...