Spring中ApplicationContextAware使用说明

ApplicationContextAware作用及如何使用 阅读详情

Spring 中提供一些Aware相关接口,像是BeanFactoryAware、 ApplicationContextAware、ResourceLoaderAware、ServletContextAware等等,实作这些 Aware接口的Bean在被初始之后,可以取得一些相对应的资源,例如实作BeanFactoryAware的Bean在初始后,Spring容器将会 注入BeanFactory的实例,而实作ApplicationContextAware的Bean,在Bean被初始后,将会被注入 ApplicationContext的实例等等。
 Bean取得BeanFactory、ApplicationContextAware的实 例目的是什么,一般的目的就是要取得一些档案资源的存取、相 关讯息资源或是那些被注入的实例所提供的机制,例如ApplicationContextAware提供了publishEvent()方法,可以支持基 于Observer模式的事件传播机制。
 ApplicationContextAware接口的定义如下:

ApplicationContextAware.java

public interface ApplicationContextAware {
    void setApplicationContext(ApplicationContext context);
}

 我们这边示范如何透过实作ApplicationContextAware注入ApplicationContext来实现事件传播,首先我们的HelloBean如下:

HelloBean.java

package onlyfun.caterpillar;

import org.springframework.context.*;
public class HelloBean implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    private String helloWord = "Hello!World!";

    public void setApplicationContext(ApplicationContext context) {
        this.applicationContext = context;
    }

    public void setHelloWord(String helloWord) {
        this.helloWord = helloWord;
    }

    public String getHelloWord() {
        applicationContext.publishEvent(
               new PropertyGettedEvent("[" + helloWord + "] is getted"));
        return helloWord;
    }
}

ApplicationContext会由Spring容器注入,publishEvent()方法需要一个继承ApplicationEvent的对象,我们的PropertyGettedEvent继承了ApplicationEvent,如下:

PropertyGettedEvent.java

package onlyfun.caterpillar;

import org.springframework.context.*;

public class PropertyGettedEvent extends ApplicationEvent {
    public PropertyGettedEvent(Object source) {
        super(source);
    }
}

 当ApplicationContext执行publishEvent()后,会自动寻找实作ApplicationListener接口的对象并通知其发生对应事件,我们实作了PropertyGettedListener如下:

PrppertyGettedListener.java

package onlyfun.caterpillar;

import org.springframework.context.*;

public class PropertyGettedListener implements ApplicationListener {
    public void onApplicationEvent(ApplicationEvent event) {
        System.out.println(event.getSource().toString());   
    }
}

 Listener必须被实例化,这我们可以在Bean定义档中加以定义:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="propertyGetterListener" class="onlyfun.caterpillar.PropertyGettedListener"/>

    <bean id="helloBean" class="onlyfun.caterpillar.HelloBean">
        <property name="helloWord"><value>Hello!Justin!</value></property>
    </bean>
</beans>

 我们写一个测试程序来测测事件传播的运行:

Test.java

package onlyfun.caterpillar;

import org.springframework.context.*;
import org.springframework.context.support.*;

public class Test {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");

        HelloBean hello = (HelloBean) context.getBean("helloBean");
        System.out.println(hello.getHelloWord());
    }
}

 执行结果会如下所示:

log4j:WARN No appenders could be found for logger 
(org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.
org.springframework.context.support.ClassPathXmlApplicationContext: 
displayName=[org.springframework.context.support.ClassPathXmlApplicationContext;
hashCode=33219526]; startup date=[Fri Oct 29 10:56:35 CST 2004]; 
root of ApplicationContext hierarchy
[Hello!Justin!] is getted
Hello!Justin!

 以上是以实作事件传播来看看实作Aware接口取得对应对象后,可以进行的动作,同样的,您也可以实作ResourceLoaderAware接口:

ResourceLoaderAware.java

public interface ResourceLoaderAware {
    void setResourceLoader(ResourceLoader loader);
}

 实作ResourceLoader的Bean就可以取得ResourceLoader的实例,如此就可以使用它的getResource()方法,这对于必须存取档案资源的Bean相当有用。
 基本上,Spring虽然提供了这些Aware相关接口,然而Bean上若实现了这些界面,就算是与Spring发生了依赖,从另一个角度来看,虽然您可以直接在Bean上实现这些接口,但您也可以透过setter来完成依赖注入,例如:

HelloBean.java

package onlyfun.caterpillar;

import org.springframework.context.*;

public class HelloBean {
    private ApplicationContext applicationContext;
    private String helloWord = "Hello!World!";

    public void setApplicationContext(ApplicationContext context) {
        this.applicationContext = context;
    }

    public void setHelloWord(String helloWord) {
        this.helloWord = helloWord;
    }

    public String getHelloWord() {
        applicationContext.publishEvent(new PropertyGettedEvent("[" + helloWord + "] is getted"));
        return helloWord;
    }
}

 注意这次我们并没有实作ApplicationContextAware,我们在程序中可以自行注入ApplicationContext实例:

ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");

HelloBean hello = (HelloBean) context.getBean("helloBean");
hello.setApplicationContext(context);
System.out.println(hello.getHelloWord());

 就Bean而言,降低了对Spring的依赖,可以比较容易从现有的框架中脱离。

原文地址:http://hi.baidu.com/java6666/item/aff06134c0af1a362e0f81ef

流体动力学仿真软件:SU2_(1).SU2简介与安装 SU2 是一个开源的计算流体动力学(CFD)和计算结构动力学(CSD)仿真软件,由斯坦福大学的航空航天系开发。它主要用于解决流体动力学问题,包括但不限于空气动力学、热力学、化学反应流等。SU2 的特点在于其高度的灵活性和可扩展性,使其成为科研和工业领域中非常受欢迎的工具。SU2 采用有限体积法(FVM)和有限元法(FEM)进行数值求解,支持多种物理模型和求解器,如 Euler 方程、Navier-Stokes 方程、RANS 方程等。 阅读详情

相关推荐

告别Keil4!手把手教你用Keil C51 V9.61编译51单片机代码(附最新激活方法)

本文详细介绍了Keil C51 V9.61在51单片机开发中的全栈升级指南,包括编译速度提升、调试器性能优化和现代开发支持等核心优势。通过智能安装方案、项目迁移实战和新特性深度应用,帮助开发者告别Keil4,大幅提升开发效率。附有最新激活方法和实用技巧,适用于嵌入式开发工程师。

weixin_26886855的博客 420

Spring之底层架构核心概念-事件发布

事件发布的两种方式 A. applicationContext.publishEvent("msg") B. 事件发布器 applicationEventPublisher.publishEvent("msg");

青苔小榭 527

AD620仪表放大器模组实战:从调零到信号放大的完整指南

本文详细介绍了AD620仪表放大器模组的实战应用,从调零到信号放大的完整指南。AD620模组以其专业级性能和易用性成为微弱信号放大的首选,集成了AD620芯片、LM358运放和7660电源转换芯片。文章提供了调零技巧、增益设置方法以及单端与差分输入的正确连接方案,并通过心电信号采集和称重传感器等实际案例展示了其广泛应用。

weixin_29290379的博客 376

ApplicationContext.publishEvent ——Java异步调用的一种方式

一、先抽象出来一个事件类继承 ApplicationEvent ,定义一个 execute 业务执行方法 /** * @author sukang */ public abstract class AbstractEvent extends ApplicationEvent { public AbstractEvent(Object source) { super(source); } /** * 事件执行方法 */ protected abstract void execu

sxlzs_的博客 9236

基于STM32的3D打印机控制

通过本项目,我们成功搭建了一个基础的3D打印机控制系统,能够控制步进电机和加热元件。这为使用STM32开发功能丰富的3D打印机提供了基础,您可以在此基础上继续扩展功能,如增加LCD显示、SD卡存储、联网控制等功能。在这个项目中,我们将使用STM32微控制器开发一个基础的3D打印机控制系统。通过控制步进电机、加热元件和温度传感器,我们将实现一个简单的FDM(熔融沉积制造)3D打印机控制。- 检查PWM信号的生成功能,确认加热元件的控制逻辑是否正常。- 增加适当的滤波和校准算法,以提高温度读取的准确性。

2401_88938661的博客 1503

自学篇--使用keil5.23创建一个stm32工程并编译(固件包自带版本)

之前在本科学习阶段学习过一点51单片机的知识,可是因为基本没有实践过几次现在已经完全忘记了。。前几天老师突然丢给我几个板子说让我把程序编译、烧写环境装好,当时我就震惊了,不过经过三四天的自我摸索,之后参考他人的学习经验,现在已经基本能处理这个问题了,所以为了方便后面的学者,主要也是为了把自己这几天的学习成果记录一下,我在这里把这个过程写下来。(因为刚刚接触,很多原理性的东西都还不懂,只是一个操作步

yang_csdnForOBTS的博客 8659

Spring的ApplicationContextAware的使用

Spring的ApplicationContextAware的使用1 问题引入2 ApplicationContextAware的简介3 使用场景 Spring中ApplicationContextAware主要用来获取Spring上下文已经实例化的Bean对象 1 问题引入 项目使用Spring管理各个实例对象Bean, 如果为了使用已被实例化的Bean对象,如果使用再次加载配置文件的方法,可能会出现一个问题,如一些线程配置任务, 会启动两份,产生了冗余. ApplicationContext app

ABestRookie的博客 7456

从PLC到机械臂:揭秘工业自动化中的信号交互与控制逻辑

本文深入解析了PLC与机械臂在工业自动化中的信号交互与控制逻辑,详细介绍了硬件连接方案、通信机制及控制逻辑设计。通过西门子PLC与六轴机械臂的实战案例,展示了从信号采集到动作执行的完整流程,并探讨了高级控制策略与行业应用前景,为工程师提供了一套完整的实践框架。

weixin_29304985的博客 388

ApplicationContextAware接口提供了publishEvent方法,实现了Observe(观察者)设计模式的传播机制,实现了对bean的传播...

新增要操作的对象bean import org.springframework.context.ApplicationEvent; public class AddEvent extends ApplicationEvent{ private String name; public AddEvent(Object source,String name) { super(s...

weixin_30951743的博客 479

3DGS-to-PC实战指南:零代码实现3D高斯场景到点云/Mesh的高效转换

本文详细介绍了3DGS-to-PC工具如何实现3D高斯场景到点云/Mesh的高效转换,无需代码即可完成。通过实战案例和参数调优技巧,帮助用户快速掌握这一开源插件的使用方法,提升3D数据处理效率。特别适合建筑扫描、影视特效等领域的专业人士。

q1w3e5r7t9y的博客 273

python基于语音识别的智能垃圾分类系统

大家好我是蓝天,混迹在java圈的辛苦码农。今天要和大家聊的是一款《python基于语音识别的智能垃圾分类系统》毕业设计项目。项目源码以及部署相关请联系蓝天,文末附上联系信息。🎈作者:蓝天🎈🎈个人简介:精通 Java、Python、C#、C、C++ 等编程语言,同时对微信小程序、Php 和 Android 等技术也能熟练掌握,可为大家提供全面的技术支持与交流。我拥有丰富的成品 Java、Python、C# 毕业设计项目经验,能够为学生提供各类个性化的开题框架及实际运作方案。🎈。

Chujun123528的博客 660

观察者模式:Spring之publishEvent的使用

用观察者模式中的publishEvent实现。

weixin_49374214的博客 1441

【数字IC刷题】华为海思数字IC笔试题(1)详细解析版

【数字IC刷题】华为海思数字IC笔试题(1)详细解析版

MoorePlus的博客 4220

Spring Boot 中的 Aware 接口以及 ApplicationContextAware 的详细说明、使用示例及注意事项

Spring Boot 中的 Aware 接口以及 ApplicationContextAware 的详细说明、使用示例及注意事项

爱的叹息的专栏 2083

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Spring中ApplicationContextAware接口使用理解说明

一、APPLICATIONCONTEXTAWARE的作用 1、APPLICATIONCONTEXT是什么? 很多人都知道,ApplicationContext是我们常用的IOC容器,而他的顶层接口便是BeanFactory,ApplicationContext对BeanFactory做了拓展,功能更加强大。 2、APPLICATIONCONTEXTAWARE作用 在Spring/SpringMVC中,我们拿到IOC容器无非有三种方式,那就是使用ApplicationContext接口下的三个实现类:

李云龙的意大利面 1274

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

AI Skill录制原理与实操:语义化自动化入门指南

AI Skill是一种将人工操作转化为可复用自动化单元的技术概念,其核心在于视觉语义理解与操作意图建模,而非传统录屏或脚本编程。通过UI元素的语义锚定、轻量状态机决策和沙盒化运行环境,实现跨页面、跨分辨率、高容错的Web端自动化。该技术显著降低RPA使用门槛,适用于运营、HR、财务等高频重复场景的数据搬运、状态同步与报表生成,是当前面向非技术人员的轻量化流程自动化主流方案。本文聚焦豆包Skill的落地实践,详解其如何以‘所见即所录’方式实现真正开箱即用的AI自动化。

weixin_34310369的博客 152

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Spring之Bean实现了ApplicationContextAware等aware接口,对于setApplicationContext方法执行时间点的说明

对于实现了Aware接口的Bean对象,如: public class beanTest implement ApplicationContextAware { private static ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext app

fycghy0803的专栏 6696

关于Spring几个特殊类的说明与备忘(BeanNameAware\ApplicationContextAware\InitializingBean\DisposableBean)

关于Spring几个特殊类的说明与备忘 applicationContext.xml        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.spr

多言数穷,不如守中。十语九中,未必称奇;一语未中,愆尤骈集。 2万+

Spring应用 4 ApplicationContextAware应用理解

Spring应用 4 ApplicationContextAware应用理解 Aware接口的Bean在被初始之后,可以取得一些相对应的资源。 Aware接口本身并不具备什么功能,一般是用于子类继承后,Spring上下文初始化bean的时候会对这个bean传入需要的资源。 例如ApplicationContextAware接口,可以在Spring初始化实例 Bean的时候,可以通过这个接口将当...

u011679955的博客 280

Spring中ApplicationContextAware的作用

ApplicationContextAware通过它Spring容器会自动把上下文环境对象调用ApplicationContextAware接口中的setApplicationContext方法。 我们在ApplicationContextAware的实现类中,就可以通过这个上下文环境对象得到Spring容器中的Bean。   看到—Aware就知道是干什么的了,就是属性注入的,但是这个Ap...

weixin_30292843的博客 92

Spring中ApplicationContextAware接口的使用

一、这个接口有什么用?当一个类实现了这个接口(ApplicationContextAware)之后,这个类就可以方便获得ApplicationContext中的所有bean。换句话说,就是这个类可以直接获取spring配置文件中,所有有引用到的bean对象。二、怎么使用这个接口?例如我有一个方法类UserUtil,这个方法类中需要使用到的ApplicationContext中的某个bean(app...

u013619689的专栏 594

ApplicationContextAware接口的作用

  1/============== 在Web应用中,Spring容器通常采用声明式方式配置产生:开发者只要在web.xml中配置一个Listener,该Listener将会负责初始化Spring容器,MVC框架可以直接调用Spring容器中的Bean,无需访问Spring容器本身。在这种情况下,容器中的Bean处于容器管理下,无需主动访问容器,只需接受容器的依赖注入即可。 但在某些特殊的情况...

weixin_33696106的博客 102

Spring中 DisposableBean | ApplicationContextAware 使用

关于在spring容器初始化 bean 和销毁前所做的操作定义方式有三种: 第一种:通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 第二种是:通过在xml中定义init-method 和destory-method方法 第三种是:通过bean实现InitializingBean和 DisposableBean接口 例如:Tra...

qq_37109975的博客 328

ApplicationContextAware

通过实现这个接口,bean 可以主动访问 Spring 容器,从而可以动态获取其他 bean、资源文件或容器相关信息。是 Spring 框架中的一个接口,用于让 bean 能够获取到 Spring 容器的。当一个 bean 实现该接口后,Spring 容器会在初始化该 bean 时,自动调用。可以获取bean、资源、环境配置。方法,并将容器自身的。

287
上一篇: Dubbo 对配置文件的解析
下一篇: ApplicationContextAware接口
weiythi
博客等级 码龄16年 23粉丝 48原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值