Example of BeanFactoryAware in Spring--转
原文地址:http://www.concretepage.com/spring/example_beanfactoryaware_spring
If a bean in spring implements BeanFactoryAware then that bean has to implement a method that issetBeanFactory. And when that bean is loaded in spring container, setBeanFactory is called. BeanFactoryAware belongs to the package org.springframework.beans.factory. BeanFactoryAware awares the bean for its BeanFactory.
A.java
package com.concretepage;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
public class A implements BeanFactoryAware{ @Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
System.out.println("setBeanFactory:"+beanFactory);
}
public A(){
System.out.println("Bean A is Initialized.");
}
}
app-conf.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd "> <bean id="testA" class="com.concretepage.A"/> </beans>
SpringTest.java
package com.concretepage;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringTest {
public static void main(String[] args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("app-conf.xml");
context.registerShutdownHook();
}
}
Output
Bean A is Initialized.
setBeanFactory:org.springframework.beans.factory.support.DefaultListableBeanFactory@16df1832: defining beans [testA]; root of factory hierarchy
Example of BeanFactoryAware in Spring--转的更多相关文章
- 69 Spring Interview Questions and Answers – The ULTIMATE List--reference
This is a summary of some of the most important questions concerning the Spring Framework, that you ...
- Spring的Bean的生命周期
一:生命周期执行的过程如下:1) spring对bean进行实例化,默认bean是单例.2) spring对bean进行依赖注入.3) 如果bean实现了BeanNameAware接口,spring将 ...
- 【Spring IoC】Spring Bean(三)
一.Spring Bean的定义 被称作 bean 的对象是构成应用程序的支柱也是由 Spring IoC 容器管理的.bean 是一个被实例化,组装,并通过 Spring IoC 容器所管理的对象. ...
- Spring IOC -bean对象的生命周期详解
生命周期执行的过程如下:1) spring对bean进行实例化,默认bean是单例2) spring对bean进行依赖注入3) 如果bean实现了BeanNameAware接口,spring将bean ...
- Spring学习(一)--简化Java开发,认识Spring
一.传统Java开发弊端 在传统的开发之中,任何一个有实际意义的应用都会由两个或更多的类所组成,这些类之间相互协调来完成特定的业务逻辑,按照传统的做法,每个对象负责管理与自己相互协作的对象(即他所依赖 ...
- spring之BeanFactoryAware接口
springBeanFactoryAware (转)要直接在自己的代码中读取spring的bean,我们除了根据常用的set外,也可以通过spring的BeanFactoryAware接口实现,只要实 ...
- Spring Aware接口---BeanNameAware BeanFactoryAware ApplicationContextAware
前言 对于应用程序来说,应该尽量减少对spring api的耦合程度,然后有时候为了运用spring提供的一些功能,有必要让bean了解spring容器对其管理的细节信息,如让bean知道在容器中是以 ...
- spring扩展点之四:Spring Aware容器感知技术,BeanNameAware和BeanFactoryAware接口,springboot中的EnvironmentAware
aware:英 [əˈweə(r)] 美 [əˈwer] adj.意识到的;知道的;觉察到的 XXXAware在spring里表示对XXX感知,实现XXXAware接口,并通过实现对应的set-XXX ...
- 学习AOP之透过Spring的Ioc理解Advisor
花了几天时间来学习Spring,突然明白一个问题,就是看书不能让人理解Spring,一方面要结合使用场景,另一方面要阅读源代码,这种方式理解起来事半功倍.那看书有什么用呢?主要还是扩展视野,毕竟书是别 ...
- 学习AOP之深入一点Spring Aop
上一篇<学习AOP之认识一下SpringAOP>中大体的了解了代理.动态代理及SpringAop的知识.因为写的篇幅长了点所以还是再写一篇吧.接下来开始深入一点Spring aop的一些实 ...
随机推荐
- [转]WinForms GridListEditor - How to restore values in the auto filter row
http://dennisgaravsky.blogspot.hk/2016/05/winforms-gridlisteditor-how-to-restore.html using System; ...
- 【转】Wince中文乱码解决方法
http://www.cnblogs.com/we-hjb/archive/2008/11/27/1342651.html 如果WinCE的默认语言是英语,也没有支持MUI的话,很多中文的应用程序就不 ...
- LNMP编译安装基于centos7.2
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...
- Linux(centeros)下安装jdk
首先需要说明的是有的Linux系统自带jdk,这个jdk是openjdk,可以通过java-version查看 所以安装的步骤是,首先删除系统自带的(如果有)openjdk 1. rpm -qa | ...
- 字符串混淆技术在.NET程序保护中的应用及如何解密被混淆的字符串
Visual Studio提供的Dotfuscator保护程序,可以对用户代码中包含的字符串进行加密.比如下面的例子,为了找到这个程序的注册算法,用.NET Reflector加载程序集后,发现代码中 ...
- 使用WPF动态生成Code 39条形码
最近在看些条形码方面相关的资料,而如果只是看的话,效果似乎并不怎么好,所以决定动手做点Demo,以增强对相关知识的记忆. 这里是一个我编写的使用WPF生成Code 39的例子,Code 39的编码很简 ...
- Guava - 并行编程Futures
Guava为Java并行编程Future提供了很多有用扩展,其主要接口为ListenableFuture,并借助于Futures静态扩展. 继承至Future的ListenableFuture,允许我 ...
- 实现tip浮层
实现简单的tip浮层: html代码: <!doctype html> <html> <head> <meta charset="utf-8&quo ...
- redis(一) 安装以及基本数据类型操作
redis(一) 安装以及基本数据类型操作 redis安装和使用 redis安装 wget http://download.redis.io/redis-stable.tar.gz tar zxvf ...
- 自制Unity小游戏TankHero-2D(3)开始玩起来
自制Unity小游戏TankHero-2D(3)开始玩起来 我在做这样一个坦克游戏,是仿照(http://game.kid.qq.com/a/20140221/028931.htm)这个游戏制作的.仅 ...