总结下ServletContext和ApplicationContext

Web工程中获取ServletContext和ApplicationContext的方法以及相关Aware的使用 1、在Web环境下获取ServletContext 利用ContextLoader WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext(); ServletContext servletContext = webApplicationContext.get... 阅读详情

一、ServletContext是什么?

ServletContext是一个web应用的上下文,是一个全局信息的存储空间,代表当前web应用。

二、ServletContext什么时候创建?

ServletContext在web应用(服务器)启动时创建。

三、ServletContext什么时候销毁?

ServletContext在Web应用(服务器)关闭时释放。

四、ServletContext包含哪些东西?

可以debug源码看一下:


其中parameters参数是web.xml配置文件中<context-param></context-param>节点内容,通过转换为key-value的形式存在ServletContext中。

五、ServletContext与Spring容器(ApplicationContext)的关系(第三步ApplicationContext创建过程会在以后详细介绍)?

1、ServletContext创建之后,然后读取<context-param></context-param>节点内容;

2、触发ServletContextEvent事件,ServletContextListener监听这个事件,ServletContextListener有两个抽象方法,分别是ServletContext初始化时调用方法和ServletContext销毁时调用的方法。

public interface ServletContextListener extends EventListener {
    void contextInitialized(ServletContextEvent var1);

    void contextDestroyed(ServletContextEvent var1);
}

3、ContextLoaderListener实继承ContextLoader并实现ServletContextListener,所以也监听ServletContextEvent事件,事件触发后ContextLoaderListener会执行初始化方法。

@Override
public void contextInitialized(ServletContextEvent event) {
	initWebApplicationContext(event.getServletContext());
}

六、Spring容器(ApplicationContext)创建过程?

1、ContextLoaderListener监听ServletContextEvent事件,执行初始化contextInitialized(ServletContextEvent event)方法;

2、先判断是否已经创建过ApplicationContext;

if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
		throw new IllegalStateException(
			"Cannot initialize context because there is already a root application context present - " +
				"check whether you have multiple ContextLoader* definitions in your web.xml!");
}

3、创建WebApplicationContext对象(Spring容器);

if (this.context == null) {
		this.context = createWebApplicationContext(servletContext);
}

4、转换成ConfigurableWebApplicationContext 对象;

ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;

5、执行configureAndRefreshWebApplicationContext方法,封装ApplicationContext上下文数据,其中会从ServletContext中读取applicationContext.xml配置,调用refresh方法完成所有bean的解析初始化创建。

configureAndRefreshWebApplicationContext(cwac, servletContext);
 //从ServletContext中读取applicationContext.xml配置
String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM);
if (configLocationParam != null) {
	wac.setConfigLocation(configLocationParam);
}

.....

//初始化相关bean并创建java对象
customizeContext(sc, wac);
wac.refresh();

6、ConfigurableWebApplicationContext 创建之后放到ServletContext中;

servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

六、bean的解析初始化创建过程没有详细,感兴趣的可以看下源码。


从Si3N4到SiNx:一文搞懂芯片制造中氮化硅的化学式玄机(附工艺参数影响) 本文深入探讨了芯片制造中氮化硅(SiNx)化学式的调控艺术,揭示了从Si3N4到SiNx的转变如何影响材料性能。通过分析PECVD和PVD工艺参数对x值的精确调控,以及x值对电学和机械性能的影响,为半导体制造提供了实用的工艺优化策略。 阅读详情

相关推荐

腾讯云运维工程师认证TCA--真题(最新2022.11)

解析:云原生应用的12要素,1.基准代码:一份基准代码,多份部署;解析:腾讯云主账号具备对其名下资源(包括存储桶)的最大权限,您虽然可以在存储桶策略中限制几乎所有操作,但主账号始终具备 PUT Bucket Policy 操作的权限,主账号调用该操作不检查存储桶策略。解析:瀑布模型将软件生命周期划分为制定计划、需求分析、软件设计、程序编写、软件测试和运行维护等六个基本活动,并且规定了它们自上而下、相互衔接的固定次序,如同瀑布流水,逐级下落。解答:云原生五大关键技术:微服务、容器化、DevOps、持续交付。

e1210101的博客 9915

ServletContext与ApplicationContext的区别

Spring中的概念 在阅读Spring源码或相关的文献时,经常会遇到WebApplicationContext, ApplicationContext, ServletContext以及ServletConfig等名词,这些名词都很相近,但适用范围又有所不同,对理解源码及spring内部实现造成混淆,因此有必要对这些概念进行一些比较. 为了后续比较的方便,首先我们先来澄清这几个名词的概念 ...

u010325193的博客 1万+

智驾系统分层架构:从传感器到执行器的全链路解析

本文深入解析了智能驾驶系统的分层架构,从传感器数据采集融合、应用层决策到车辆管理层执行,完整呈现了从感知到控制的全链路工作流程。文章重点阐述了架构设计的核心优势在于接口标准化与模块解耦,以ACC和LKA协同场景为例,说明了各层级如何通过清晰分工与高效协作,实现复杂系统的可靠、灵活与易于升级。

weixin_29219189的博客 399

ServletContext(Application)

ServletContext(Application),代表整个应用 一个项目只有一个ServletContext对象,可以在N个Servlet中来获取这个唯一的对象,使用它可以给Servlet传递数据。 ServletContext在服务器启动时创建,在服务器关闭时销毁,一个JavaWeb只创建一个ServletContext对象。 ServletContext的功能就是获取全局配置信息、多个Servlet之间共享数据、获取资源路径。 获取ServletContext Servlet#getSe

水手的博客 739

深入GD32/STM32引脚复用:你的JTAG/SWD接口是怎么‘消失’的?一次讲清原理与预防

本文深入解析GD32/STM32调试接口(JTAG/SWD)突然失效的原理与预防措施。通过分析MCU启动流程、引脚复用机制及典型错误代码模式,揭示调试接口'消失'的根本原因,并提供硬件设计检查清单、软件防护代码及开发流程优化方案,帮助开发者有效避免烧录失败问题。

weixin_42532938的博客 369

【保姆级教程】教你如何轻松获取MIMIC数据使用权限

文章非常详细地介绍了MIMIC数据库申请使用的全部步骤。

越努力 越幸运 6600

Servlet、ServletConfig、ServletContext、DispatcherServlet、ApplicationContext、WebApplicationContext区别?

Tomcat 是 Web 应用服务器,一个 Servlet 容器,Tomcat 作为 Servlet 容器,负责处理客户端请求,把请求传给 Servlet ,并将 Servlet 的响应返回给客户端。DispatcherServlet 本质上就是一个特殊的 Servlet , web.xml 经过上述加载过程配置其他 Servlet,例如 DispatcherServlet,然后会找到 WebApplicationContext 容器,并把它作为自己的上下文。

u011047968的专栏 1227

C/C++基础讲解(四十三)之图形篇之绘制直线、圆、圆弧、 椭圆

程序主要是基于Visual studio 2019进行编译完成了,有兴趣的小伙伴可以自己安装下Visual studio 2019,网上有现成的教程,当然了,如果有问题,也可以和我联系,这里我们主要讲解些源码实例,不多说了,言归正传。 C语言,做为学习其他语言的基础语言,其重要性就不言而喻了.下面我将和大家一起来学习探讨C语言的相关奥秘。 实例1:绘制直线 实例2:绘制圆 实例2:绘制圆弧 实例2:绘制椭圆

hnjzfwy的博客 1235

ServletContext与ApplicationContext

ServletContext,即Servlet环境对象或Servlet容器,包含从容器环境中获得的初始化信息,其内提供的属性和方法在同一web应用下的所有servelt中被使用。每一个web-app只能有一个ServeltContext,web-app可以是一个放置web application文件的文件夹,也可以是一个.war。     ApplicationContext 是Spri

乔志勇笔记 1064

RFC 字符码转换深度解析:Unicode、非 Unicode 与 MDMP 系统的协奏

老版本 MDMP 系统不上传自定义映射时,Unicode 端会落回“预配置列表”。列表里可见西欧 1100、日文 8000、中文 8400 等经典编号。若需强制覆写映射,可在 SM59 ➡Unicode页签启用,或直接勾选作为兜底。字符编码问题常“潜伏”多年,一旦旧系统升级或新增语种便集中爆发。掌握 RFC code page 转换机理、灵活运用 SM59 选项、在早期对 LANG 字段和字段长度进行治理,是根治乱码与 short dump 的关键。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 225

深度学习实战107-基于Qwen3+GraphRAG+Agent的智能文档管理系统:精准问答与决策支持

在当今信息爆炸的时代,企业面临海量文档的管理与利用挑战。传统文档管理系统虽然提供了存储和检索功能,但缺乏对文档内容的深度理解与分析能力,更难以实现基于知识的决策支持。基于多模态大模型Qwen3、GraphRAG技术与Agent框架构建的智能文档管理系统,能够突破传统限制,实现文档内容的精准解析、知识图谱的自动构建、复杂关系的推理分析以及决策建议的生成,为企业知识管理带来革命性变革。

微学AI的博客 866

ServletContext和ApplicationContext有什么区别

两者的区别就是application用在jsp中,servletContext用在servlet中。application和page request session 都是JSP中的内置对象,在后台用ServletContext存储的属性数据可以用 application对象获得。...

weixin_66387650的博客 825

开源模型应用落地-qwen模型小试-Qwen3-8B-快速体验(一)

阿里云推出国内首个集成“快思考”与“慢思考”能力的 Qwen3-8B 大语言模型,以80亿参数和 128K 上下文支持,重塑AI应用边界并助力开发者高效部署

以微薄之力,予他人些许温暖. 2万+

问:ServletContext、WebApplicationContext、ApplicationContext是什么关系?

ServletContext、WebApplicationContext和ApplicationContext是Java Web开发中的核心组件。ServletContext提供全局上下文环境,WebApplicationContext是Spring为Web应用设计的IoC容器,继承自ApplicationContext并增加Web特性。三者相互关联,WebApplicationContext作为属性存于ServletContext,且可访问ApplicationContext中的Bean,共同支持Web应

技术铺掌柜 1809

深度学习工具包 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")

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ApplicationContext 、servletcontext和DispatcherServlet

首先,对于一个web应用,其部署在web容器中,web容器提供其一个全局的上下文环境,这个上下文就是ServletContext,其为后面的spring IoC容器提供宿主环境; 其次,在web.xml中会提供有contextLoaderListener。在web容器启动时,会触发容器初始化事件,此时contextLoaderListener会监听到这个事件,其contextInit

春风十米的博客 1774

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

ServletContext、ApplicationContext、WebApplicationContext三者区别

ServletContext:Servlet容器(Tomcat、Jboss等)需要给项目初始化一个ServletContext作为公共环境容器存放公共信息,而ServletContext中的信息都是由容器提供的。 WebApplicationContext:是继承于ApplicationContext的一个接口。扩展了ApplicationContext,是专门为Web应用准备的,它允许从相对于Web根目录的路径中装载配置文件完成初始化。 ApplicationContext:是 Spring ...

jxlxx_023的博客 1150

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

ServletContext 中的 context 字段和ApplicationContext 中的 context 字段(此时该字段的类型为 StandardContext)有什么区别

中的context字段类型为。用于连接和 Tomcat 的内部实现。中的context字段类型为。用于连接和 Tomcat 的。区别的context字段是较高层次的抽象,提供对 Web 应用资源的访问。的context字段是较低层次的实现,负责管理 Web 应用的生命周期和组件。

fanjinhong_8521的博客 970

Servletcontext,ApplicationContext和DispatcherServlet间的区别

Servletcontext 说道Servletcontext,首先需要了解浏览器请求web的过程 1.浏览器发送http请求到web容器。并将请求发送给tomcat等web容器。 2.tomcat将http请求封装成httpServletRequest并发送给web项目。 而Servletcontext就是tomcat给web项目创建的全局环境。他有以下特点 1.全局共享数据。 2.包含着we...

小鲍侃java 1788

pageContext/ServletContext/ApplicationContext/ServletActionContext

pageContext/ServletContext/ApplicationContext/ServletActionContext  pageContext pageContext对象是javax.servlet.jsp.PageContext实例,pageContext对象 这个对象代表页面上下文,该对象主要用于访问JSP之间的共享数据。使用pageContext可以访

G1248019684的专栏 1615

ApplicationContext和ServletContext

ApplicationContext和ServletContext 转自:http://www.cnblogs.com/tuhooo/p/6491903.html ServletContext与Web应用以及Spring容器启动 一、ServletContext对象获取Demo Servlet容器在启动时会加载Web应用,并为每个Web应用创建唯一的ServletC

看不过的黑工坊 1425

从Spring的Bean中获取servletcontext 和 applicationContext

import javax.servlet.ServletContext;    import org.springframework.context.ApplicationContext;  import org.springframework.context.ApplicationContextAware;  import org.springframework.web.context.ServletContextAware;    /**   * @作者 黄嘉寅   * @功能 客户端与服务端数据传

1135
上一篇: 如何线程安全的使用HashMap
下一篇: Jackson2JsonRedisSerializer和GenericJackson2JsonRedisSerializer的区别
baisq2017
博客等级 码龄10年 14粉丝 19原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值