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的一些实 ...
随机推荐
- [java基础]java中static关键字
1.static概念 static是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中任何变量或者代码都是在编译时由系统自动分配内存来存储的,而所谓静态就是指在编译后所分配的内存会一直存在,直到程序 ...
- 套题 codeforces 360
A题:Opponents 直接模拟 #include <bits/stdc++.h> using namespace std; ]; int main() { int n,k; while ...
- 工作当中实际运用(2)——js原生实现全选/反选
老规矩 直接上代码 代码中详细注释: function checkAll(){ var alls=document.getElementById('tab-stp').getElementsByTa ...
- android precelable和Serialization序列化数据传输
一 序列化原因: 1.永久性保存对象,保存对象的字节序列到本地文件中:2.通过序列化对象在网络中传递对象:3.通过序列化在进程间传递对象. 二 至于选取哪种可参考下面的原则: 1.在使用内存的时候,P ...
- 【WPF】如何把一个枚举属性绑定到多个RadioButton
一.说明 很多时候,我们要把一个枚举的属性的绑定到一组RadioButton上.大家都知道是使用IValueConverter来做,但到底怎么做才好? 而且多个RadioButton的Checked和 ...
- ArcEngine 无法嵌入互操作类型
说明: 在.net 4.0中,声明 IPoint point = new PointClass();会出现下面这个错误 错误 2 类型"ESRI.ArcGIS.Geometry.PointC ...
- 我的ORM之一 -- 查询
我的ORM索引 概述 http://code.taobao.org/svn/MyOql/ 这是我自己写的开源ORM教程,我想先从场景示例中切入介绍,先有一个感性的认识,以小见大,触类旁通,有了这个认识 ...
- [.net 面向对象程序设计进阶] (3) 正则表达式 (二) 高级应用
[.net 面向对象程序设计进阶] (2) 正则表达式 (二) 高级应用 上一节我们说到了C#使用正则表达式的几种方法(Replace,Match,Matches,IsMatch,Split等),还 ...
- vpn establish capability from a remote deskstop is disabled错误的解决办法
使用Cisco的VPN时,有时候会提示vpn establish capability from a remote deskstop is disabled.这样的错误,解决办法就是重启本机的Remo ...
- 【转载】关于sql server 代理(已禁用代理xp)
原文地址:http://blog.sina.com.cn/s/blog_493cafbb0100qy91.html 症状: SQL SERVER2005里面,启动SQL代理服务,启动正常,但是在sql ...