Spring-3 ApplicationContext

spring3.0以后移除ContextLoaderServlet,使用ContextLoaderListener获取ApplicationContext Spring3.0以后就找不到ContextLoaderServlet这个类了。跟了一下包也确实没有ContextLoaderServlet这个类了。 然后想确认一下查看 spring changelog 果然。 Changes in version 3.0.0.M1 (2008-12-05) ---------------------------------------- * revis 阅读详情

Spring容器的最基本接口就是BeanFactory,它有一个子接口:ApplicationContext,称Spring上下文。

BeanFactory包含以下5个方法: 

- boolean       containsBean(String name):         Spring容器中是否包含id为name的bean 

- < T>T          getBean(Class<> requied Type):  该类型时,对象唯一可以获取 

- Object         getBean(String name)

 - <T> T         getBean(String name, Class requiedType)

 - Class<?>   getType(String name)

ApplicationContext包含BeanFactory的全部功能,还有额外的功能,通常不会使用BeanFactory,建议使用ApplicationContext。

ApplicationContext的额外功能:

一、默认初始化suoyou所有singleton Bean,也可以通过配置取消。

        当系统创建ApplicationContext时,默认会预初始化所有的singleton Bean。包括调用构造器创建实例,及根据<property>执行setter方法,意味着系统前期开销大。

bean:

package codeEETest;
public class Person
{
	public Person()
	{
		System.out.println("==正在执行Person无参数的构造器==");
	}
	public void setTest(String name)
	{
		System.out.println("正在调用setName()方法,传入参数为:" + name);
	}
}
xml:

<bean id="chinese" class="codeEETest.Person">
	<!-- 驱动Spring执行chinese Bean的setTest()方法,以"孙悟空"为传入参数 -->
	<property name="test" value="孙悟空"/>
</bean>
即使主程序只有一行代码,即创建容器:
ApplicationContext ctx = new ClassPathXmlApplicationContext("codeEETest/beans.xml");

Spring容器仍然会初始化Bean,结果:

==正在执行Person无参数的构造器==
正在调用setName()方法,传入参数为:孙悟空


为了防止初始化,配置lazy-init="true"

	<bean id="chinese" class="codeEETest.Person" lazy-init="true">
		<!-- 驱动Spring执行chinese Bean的setTest()方法,以"孙悟空"为传入参数 -->
		<property name="test" value="孙悟空"/>
	</bean>

二、ApplicationContext事件机制



【鸿蒙游戏上架审核规范指南】 华为鸿蒙游戏上架审核规范指南摘要 阅读详情

相关推荐

保姆级教程:IAR for STM8 3.11版本安装与破解全流程(附资源包)

本文提供IAR for STM8 3.11版本的详细安装与破解教程,涵盖环境准备、主程序安装、许可配置及实战验证全流程。针对新手常见问题,如许可证报错、驱动安装失败等,给出了具体解决方案,帮助开发者快速搭建稳定的STM8开发环境。

study的专栏 936

Spring学习笔记3_自定义Bean特征--ApplicationContextAware 和BeanNameAware

文章参考来源:Spring Framework官方文档 Spring框架本身提供了许多接口,允许用户使用这些接口自定义bean的性质。归结如下: 生命周期回调 ApplicationContextAware 和BeanNameAware 其他的Aware 接口 2. ApplicationContextAware 和BeanNameAware 当ApplicationContext创建一个实现了org.springframework.context.ApplicationContextAware接口.

hahalan的博客 408

用Java实现对接豆包ai火山引擎详细版简单明了ai对话

第二部分代码实现。

m0_72637700的博客 8606

Spring中ApplicationContextAware接口的用法

1. 这个接口有什么用? 加载Spring配置文件时,如果Spring配置文件中所定义或者注解自动注入的Bean类实现了ApplicationContextAware 接口,那么在加载Spring配置文件时,会自动调用ApplicationContextAware 接口中的方法: public void setApplicationContext(ApplicationContext co

somilong的博客 2756

保姆级教程:用CST 2023一步步复现一个1-8GHz Vivaldi天线(含参数优化与结果分析)

本文提供了一份详细的CST 2023教程,指导读者如何从零开始设计并优化1-8GHz Vivaldi天线。内容涵盖工程设置、参数化建模、仿真加速技巧以及性能优化策略,特别适合需要实现宽带天线设计的工程师和研究人员。通过实战案例,帮助用户掌握Vivaldi天线的核心设计要点和CST高级功能应用。

weixin_30800987的博客 618

粒子群算法实战:用Matlab解决旅行商问题(TSP)的完整代码解析

本文提供了使用粒子群算法解决旅行商问题的完整Matlab实战指南。通过将连续空间的粒子群算法进行离散化改造,采用基于交换序的策略来更新粒子位置与速度,并给出了从问题定义、数据结构设计、核心函数实现到主迭代循环的详细代码解析。文章还探讨了参数调优、性能优化及处理复杂TSP变体的进阶思路,为物流规划、路径优化等领域的工程应用提供了可直接复用的解决方案。

m2n3o4p5的博客 350

Spring 中 ApplicationContextAware 的用法

Spring 中 ApplicationContextAware 的用法

Jaemon 510

OceanSim: 基于Isaac Sim GPU 加速水下机器人感知仿真框架

OceanSim 采用先进的基于物理的渲染技术,对水下视觉和声学传感器进行精确建模。与其他模拟引擎相比,OceanSim 的渲染速度要快得多。作为 NVIDIA Issac Sim 的扩展,OceanSim 采用了多功能设计。通过融入快速发展的 NVIDIA Omniverse 生态系统,我们的模拟器自然而然地在机器人学习和水下机器人技术之间架起了一座桥梁,从而促进了水下应用中体现型人工智能技术的开发和部署。OceanSim 将以开放源码的方式提供,使研究界能够以合作的模式作出贡献。

机器人控制与仿真应用 2048

spring中ApplicationContextAware接口

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

西楚小羽的专栏 1667

【用unity实现100个游戏之15】开发一个类保卫萝卜的Unity2D塔防游戏5(附项目源码,完结)

本期是本项目的最后一篇,主要内容是配置环境、生成不同敌人、结束重开。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2569

基于STM32的智能浇花系统毕业设计(全部资料)

摘要:本文设计了一种基于STM32单片机的智能浇花系统,集成了环境温湿度检测、土壤温湿度监测、LCD显示、Wi-Fi联网及手机APP远程控制等功能。系统通过传感器实时采集环境参数,自动控制水泵工作实现智能灌溉,同时支持用户通过手机APP远程监控和调节。论文详细阐述了硬件选型、软件设计及系统测试过程,验证了系统的稳定性和实用性。该设计为家庭园艺提供了智能化解决方案,具有节水高效、操作便捷等特点。关键词:STM32;智能灌溉;远程控制;环境监测;Wi-Fi通信。

3254968421的博客 1194

Spring中的ApplicationContextAware接口的使用

最近在看项目代码时发现一个类在项目各个地方都能进行调用,仔细研究后发现这个类实现了ApplicationContextAware这个接口,这个接口可以很方便的获取到Spring的上下文applicationContext。现在就跟我来一起看看如何使用吧。 使用方法我们先新建一个测试类AppCache,在这个类中我定义了一个静态的DictService属性。而DictService类我也提前写好了,里

catalinaLi的博客 2499

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

spring为ApplicationContext提供的3种实现

 spring为ApplicationContext提供的3种实现分别 为:ClassPathXmlApplicationContext,FileSystemXmlApplicationContext和 XmlWebApplicationContext,其中XmlWebApplicationContext是专为Web工程定制的。使用举例如下:    1. FileSystemXmlApplic

HouYing 1702

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring-3 ApplicationContext的实现

ApplicationContext的实现

陌生的博客 660

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

spring3 ApplicationContext bean spring

在用spring3时如果想用bean,则一般都是要用注解的,就是你不能直接new一个对象出来用,比如new一个dao的类,然后查数据,这样会报错。但有的时候需要new出一个对象来查数据库,我开始的时候是想尽各种办法把一个注解了的类传过来,后来在网上查了好多说怎么得到bean的方法,一直不成功,不知道为什么 。按网上说的,继承ApplicationObjectSupport,继承WebApplica

sardtass的专栏 465

Spring源码6.3 容器的功能扩展 ApplicationContext附带的功能扩展

Rush6666的博客 192

spring-framework-5.3.7配置文件applicationContext.xml的约束头

spring-framework-5.3.7配置文件applicationContext.xml的约束头着急的直接用????xsd-config.html不见了怎么办?core.html文件中可找到类似应用本文实属偏方,真有英文好的朋友找到标准的说明位置可以分享一下,我是实在搜不到了才自己找的。 着急的直接用???? <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/sch

蘑菇味的糖的博客 514

Spring4.3入门 ApplicationContext介绍

ApplicationContext 的主要实现类: ClassPathXmlApplicationContext:从 类路径下加载配置文件 FileSystemXmlApplicationContext: 从文件系统中加载配置文件 ConfigurableApplicationContext 扩展于ApplicationContext,新增加两个主要方法: refresh() close(),

Fly to sky 613

Spring源码(3)-Spring中的ApplicationContext

前面提到的BeanFactory接口和起相关的 二级三级实现,只是简单容器,我们平时 用到的最多的还是ApplicationContext接口的实现类.BeanFactory面向Spring自身,而后者是面向Spring的使用者。 ApplicationContext ApplicationContext继承的几口有很多,因此功能也就更多。 public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory,

Fujie1997的博客 477

【Spring】3、BeanFactory 和 ApplicationContext的区别

转自:http://blog.youkuaiyun.com/intlgj/article/details/5660587 在spring中,两个最基本最重要的包是 org.springframework.beans 和 org.springframework.context. 这两个包中的代码为Spring的反向控制 特性(也叫作依赖注射)提供了基础。 第一, BeanFactory BeanFactory实...

weixin_34004750的博客 82

Spring | 3.15 ApplicationContext的附加功能

3.15 ApplicationContext的附加功能 正如在介绍一章中所讨论的,org.springframework.beans.factory包提供了管理和操作bean的基本功能,包括编程方式。org.springframework.context包添加了ApplicationContext接口,它扩展了BeanFactory接口,此外还扩展了其他接口,以以更面向应用程序框架的风格提供附加...

星空下的程序猿 342

Spring bean初始化(3) - ApplicationContext

本节讲 Spring bean初始化(3) - ApplicationContext ApplicationContext和BeanFactory都是用于加载Bean的,但是项目中基本都是使用ApplicationContext,原因是它包括了BeanFactory的所有功能,并且进行了扩展,ApplicationContext初始化过程中会完成所有的单例( no-lazy-init) 的初...

ballenlee的博客 147

spring为ApplicationContext提供的3种实现分别为:ClassPathXmlApplicationContext

spring为ApplicationContext提供的3种实现分别为:ClassPathXmlApplicationContext, FileSystemXmlApplicationContext和XmlWebApplicationContext,其中 XmlWebApplicationContext是专为Web工程定制的。使用举例如下: 1. FileSystemXmlApplicationC...

小宝 168
上一篇: Spring--2.依赖注入
下一篇: Spring-4.Spring容器中的Bean
王小禾
博客等级 码龄11年 80粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值