springMVC之ContextLoaderListener分析

【MVC】SpringMVC源码分析之启动流程 Spring MVC源码分析之启动流程 阅读详情

我记得最开始接触javaWeb方面的东西大概是本科二年级吧,好几年以前了。。。那个时候课程作于需要用java写一个web,当时好像特别流行SSH框架吧,然后自己也当然要用上了。。。

好像最开始卡壳就在web.xml,不知道该怎么配置,而且也不知道这些配置都是干啥用的。。

最后好像是直接从网上copy了别人的配置文件也算是跑起来了吧。。。。

其实这篇文章主要是来看看配置文件中的一项:

	<listener> 
        <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

listener配置项,listener是干啥的呢,其实看了jetty的代码之后就知道了,servlet容器,例如tomcat,jetty啥的,会为其部署的web程序创建其专属的context,这里还有一个特别的东西是servletContext。。。在启动部署的web程序之前,先会为其创建上述的资源,然后在进行上下文的启动,其中包括载入默认的服务器的xml配置,里面有default的servlet什么的,还会载入用户定义的web.xml里面的定义的东西。。包括listener,servlet,以及初始化参数什么的。。

那么在真正启动程序之前,还会先调用listener的contextInitialized方法。。。

这里我们也就知道这个listener是干嘛用的了吧:我们申明的listener会在程序真正启动之前调用listener的contextInitialized方法,因此我们可以将一些初始化的内容放到listener里面来。。。。。


。。。好了,接下来回到springMVC,一般情况下我们在web应用中如果采用了springMVC,那么我们一般情况下会定义一个listener,也就是上面贴出来的。。。它用于为整个web程序创建根WebApplicationContext,它会默认读取WEB-INF目录下的applicationContext.xml文件,载入里面配置的bean什么的。。。而且对于以后DispatcherServlet创建的ApplicationContext,它会将刚刚创建的context设置为parent。。。。。


好了,好像前面的叙述比较多了。。。那么现在开始来看看ContextLoaderListener的代码吧,还是先来看看它的继承体系吧:



这个继承体系够简单的了吧,实现了ServletContextListener接口,然后继承了ContextLoaderListener,。。那么这里我们来看看它的contextInitialized方法吧。。。。

	//初始化方法,会在web程序context启动之前调用这个方法,其实主要就是创建整个程序的root ApplicationContext
	public void contextInitialized(ServletContextEvent event) {
		this.contextLoader = createContextLoader();
		if (this.contextLoader == null) {
			this.contextLoader = this;  //因为继承了ContextLoader,所以直接就是自己就好了
		}
		this.contextLoader.initWebApplicationContext(event.getServletContext());
	}

这个代码好像也没做什么什么事情,将当前的contextLoader指向了自己(因为当前还继承了ContextLoader),然后说白了就是调用父类的initWebApplicationContext方法,用于创建跟ApplicationContext,那么来看看这个方法是怎么实现的吧。。。

	//这里的servletcontext是容器创建的
	public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
		//"org.springframework.web.context.WebApplicationContext.ROOT"
		//首先判断当前的servletContext是否已经占用了这个属性,因为待会创建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!");
		}

		Log logger = LogFactory.getLog(ContextLoader.class);
		servletContext.log("Initializing Spring root WebApplicationContext");
		if (logger.isInfoEnabled()) {
			logger.info("Root WebApplicationContext: initialization started");
		}
		long startTime = System.currentTimeMillis();

		try {
			//父applicationcontext。如果有的话,那么待会创建的applicationContext会继承他
			ApplicationContext parent = loadParentContext(servletContext);

			this.context = createWebApplicationContext(servletContext, parent);  //创建属于这里的webApplicationContext,如果有的话,需要继承父context
			//将刚刚创建的webapplicationContext保存到servletcontext里面,key用的是"org.springframework.web.context.WebApplicationContext.ROOT"
			servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);

			//获取当前的线程上线文classLoader,在外部的servlet容器中,会为每一个web程序创建专属的classLoader,用于加载属于当前web程序的class。这里获取的就是那个
			ClassLoader ccl = Thread.currentThread().getContextClassLoader();
			//判断加载本类的加载器是否就是这个加载器,这个一般都是相等的,因为web程序下面,包括classes文件夹以及lib文件夹下面的都是这个classLoader加载的
			if (ccl == ContextLoader.class.getClassLoader()) {
				currentContext = this.context;  //将这个类型变量指向刚刚创建的webapplicationcontext
			} else if (ccl != null) {
				currentContextPerThread.put(ccl, this.context);
			}

			if (logger.isDebugEnabled()) {
				logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
						WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
			}
			if (logger.isInfoEnabled()) {
				long elapsedTime = System.currentTimeMillis() - startTime;
				logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
			}

			return this.context;  //返回刚刚刚创建的WebApplicationContext
		}
		catch (RuntimeException ex) {
			logger.error("Context initialization failed", ex);
			servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
			throw ex;
		}
		catch (Error err) {
			logger.error("Context initialization failed", err);
			servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
			throw err;
		}
	}

这部分的代码其实还算是蛮简单的了,首先判断当前的servletcontext的"org.springframework.web.context.WebApplicationContext.ROOT"属性是否已经被占用了,因为待会创建了WebApplicationContext会将其保存在servlet的这个属性。。。。然后接着就是调用createWebApplicationContext创建context了,并将其保存到servletcontext上述的属性下面,最后再这个创建的context返回,当然这里还有一些细节的东西要处理。。上面的注释就已经说的很清楚了。。。

那么接下来我们来看看createWebApplicationContext这个方法是怎么搞的吧:

	//用于创建爱webapplicationContext,这里可以理解为创建整个web程序的根context
	protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent) {
		Class<?> contextClass = determineContextClass(sc);  //首先确定应该使用哪一种具体的WebApplicationContext类型,默认情况是默认情况下是org.springframework.web.context.support.XmlWebApplicationContext
		if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
			throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
					"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
		}
		//创建要用到的context具体类型的实例
		ConfigurableWebApplicationContext wac =
				(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);

		
		
		// Assign the best possible id value.
		if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
			// Servlet <= 2.4: resort to name specified in web.xml, if any.
			String servletContextName = sc.getServletContextName();
			wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
					ObjectUtils.getDisplayString(servletContextName));
		}
		else {
			// Servlet 2.5's getContextPath available!
			try {
				String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(sc);
				wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
						ObjectUtils.getDisplayString(contextPath));
			}
			catch (Exception ex) {
				throw new IllegalStateException("Failed to invoke Servlet 2.5 getContextPath method", ex);
			}
		}
		wac.setParent(parent);
		wac.setServletContext(sc);
		//设置配置文件的地方,不过这里其实一般都不会设置的,也就是null,而是直接使用web-inf目录下的applicationContext.xml文件
		wac.setConfigLocation(sc.getInitParameter(CONFIG_LOCATION_PARAM));  //contextConfigLocation
		customizeContext(sc, wac);
		wac.refresh();    //调用refresh方法,这里会载入具体的bean的定义xml文件,读取bean的定义什么的
		return wac;
	}

这部分的代码也算是很简单吧,首先先处理一下,设置当前应该用到的具体的context类型,这里默认情况下都是XmlWebApplicationContext类型,然后再用反射创建这个类型的对象,然后再设置一些属性,最后调用refresh方法,这里默认是载入WEB-INF目录下的applicationContext.xml文件。。。

好了。。到这里为止,ContextLoaderListener是干嘛用的,以及在web.xml中配置的listener是干嘛用的就基本比较清楚了。。也算是解答了以前自己本科阶段的疑问。。。

在Docker中集成GPU监控体系 先上效果图 等文档整理出来再更 阅读详情

相关推荐

RealSense D455的标定并运行VINS-FUSION

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

qq_40186909的博客 2万+

springboot报错`check whether you have multiple ContextLoader* definitions in your web.xml!`

我们都知道web.xml是应用程序与容器的一个纽带缺少它你的应用程序便无法在容器中跑起来。那么web.xml 当然是由容器提供给外部应用程序的一个通道了,所以是否需要web.xml 还是由容器决定的,tomcat容器基于servlet规范编写的,所以最终决定容器如何加载应用理论上来说是由servlet规范的决定的。 sevlet3.0规定对于每一个应用启动时,容器会创建一个ServletContainerInitializer 实例与之对应,而应用需要实现具体的ServletContainerInitial

a807719447的专栏 1508

PotPlayer终极画质调校:深入MadVR渲染器设置,让你的显示器发挥100%潜力

本文深入探讨了如何通过MadVR渲染器优化PotPlayer的画质设置,充分发挥高端显卡和显示器的潜力。从色彩空间匹配、色深优化到HDR元数据处理,提供了一套完整的配置指南,帮助用户实现影院级视觉体验。特别适合拥有NVIDIA RTX或AMD RX系列显卡的用户进行精细调校。

weixin_42530458的博客 599

check whether you have multiple ContextLoader* definitions in your web.xml

check whether you have multiple ContextLoader* definitions in your web.xml! java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - ch

一光年 7891

论文阅读4——一种宽频带圆极化微带天线的设计

论文阅读——一种宽频带圆极化微带天线的设计(现在才觉得开始弄懂了一点,懂了一点之后又更糊涂了……)

weixin_64612422的博客 2316

C++详解 二叉树的三种遍历方式

上一篇文章,讲了二叉树的创建——C++实现 链表存储二叉树 接下来讲解二叉树的三种遍历方式:先序(前序)遍历、中序遍历、后序遍历,三种方式都是DFS(Depth First Search)深度优先搜索,核心思想都是函数的递归(栈),如果你能理解上面这篇文章中创建二叉树的具体过程,那么遍历就轻而易举 1.先序遍历 Former_Order_Traversel(BinTree_Node* p) { ...

weixin_43335392的博客 5371

spring boot遇到的问题

1.cannot initialize context because there is already a root application context present - check whether you have multiple contextloader* definitions in your web.xml! 解决方案:我这个工程spring boot里没有web.xml。 ...

baicp3的专栏 1880

【DeepSeek应用实践】手把手教程:用 AnythingLLM + Ollama + DeepSeek-R1 搭建本地企业知识库

在众多的技术方案中,我们选择了 AnythingLLM、Ollama 和 DeepSeek-R1 这一组合来搭建本地知识库。Ollama 作为一个轻量级的本地化大语言模型部署工具,支持多种模型,易于安装和使用,能够快速在本地运行强大的语言模型。DeepSeek-R1 是一个专为知识库问答设计的检索增强生成(RAG)模型,它结合了检索和生成的优势,能够快速从知识库中检索相关信息并生成精准答案。而 AnythingLLM 则是一个用户友好的界面工具,可以方便地连接 Ollama 和 DeepSeek-R1

寻道AI,探索AI无限可能! 2566

springMVC源码分析--容器初始化(一)ContextLoaderListener

在spring Web中,需要初始化IOC容器,用于存放我们注入的各种对象。当tomcat启动时首先会初始化一个web对应的IOC容器,用于初始化和注入各种我们在web运行过程中需要的对象。当tomcat启动的时候是如何初始化IOC容器的,我们先看一下在web.xml中经常看到的配置: [html] view plain copy  print?

江南@风少的博客 460

【功能安全】软件安全架构

目录01 软件安全架构介绍02 软件架构设计模板03 软件架构设计示例 软件架构设计的目的 软件架构设计的原则 软件架构设计输入与输出 软件架构设计的要求 注:软件架构设计和软件安全要求之间的双向可追溯性。软件架构设计原则: 软件架构静态/动态设计(参考秒尼科技术) 软件架构静态设计 软件架构动态设计 软件分层架构设计 软件架构设计安全机制错误探测的安全机制 其中:数据的范围检查指输入输出数据的范围进行检查,例如:在程序中我们可以通过数据范围来排除数据的正确性;合理性检查 例如:使用参

weixin_36460584的博客 511

【DaVinci Developer专题】-8-创建一个枚举Enum ADT(Application Data Type)

目录 1 创建一个枚举Value ADT(Application Data Type) 1.1 命名application data type 1.2 创建一个computation method计算方法属性 1.3 创建一个Contraint约束条件属性 2 创建了一个新的Type Mapping Sets 3 创建了一个S/R Port Interface 4 SWC引用Type Mapping set 5 导入CFG生成代码的总结 6 结尾 <--返回「实战篇」博文-总目录-

「汽车电子助手」的博客 2291

spring项目中监听器作用-ContextLoaderListener

作用:在启动Web 容器时,自动装配Spring applicationContext.xml 的配置信息。Spring框架启动入口。 因为它实现了ServletContextListener 这个接口,在web.xml 配置这个监听器,启动容器时,就会默认执行它实现的方法。在ContextLoaderListener 中关联了ContextLoader 这个类,所以整个加载配置过程由Conte

Mr__XiaoBai的专栏 1004

matlab 一维相位解缠

一维相位解缠算法的matlab代码实现。

点云侠的博客 372

SpringMVC源码分析(二)——ContextLoaderListener

ContextLoaderListener继承结构图 标题 一、对于SpringMVC功能实现的分析,我们首先从web.xml开始,在web.xml文件中我们首先配置的就是ContextLoaderListener,那么它所提供的功能有哪些又是如何实现的呢? 当我们使用编程方式的时候我们可以直接将Spring配置信息作为参数传入Spring容器中,如: ApplicationContext ac ...

qq_53836264的博客 632

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

springmvc从入门到源码分析专题2_tomcat服务启动过程中如何加载ContextLoaderListener的

返回专题目录 springmvc从入门到源码分析专题2_tomcat服务启动过程中如何加载ContextLoaderListener的 前言 在上一篇文章中我们做了相关前期准备,并且搭建好了我们的项目环境,成功运行了我们第一个springmvc项目helloword,但是我们并没有对我们的配置文件中的配置进行详解和分析,本篇文章及后面的文章我们将分析讲解这些配置的作用,并深入到源码讲解这些配置是如何实现的 ServletContext的作用 这里首先来说一下ServletContext的作用,因为它对后

u013328649的博客 323

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

深入源码分析SpringMVC底层原理(一)

初识SpringMVC与其初始化 文章目录初识SpringMVC与其初始化1. 初探SpringMVC基本流程2. ContextLoaderListener3.DispatcherServlet3.1 初始化WebApplicationContext3.2 刷新4. 小结 1. 初探SpringMVC基本流程 先来看一张图(引用自《Spring实战》第四版 ): 这张图大致描述了SpringM...

|-| [- |_ |_ () 2150

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【springmvc】SpringMVC启动流程及源码分析

上节说到SpringMVC在启动过程中向WEB容器中注入了两个对象: ContextLoaderListener:由AbstractContextLoaderInitializer注入。 DispatcherServlet:由AbstractDispatcherServletInitializer注入。 下面分别分析这两个对象在WEB容器启动时做了什么工作? ContextLoaderListener初始化父容器 ContextLoaderListener实现了Servlet规范中的javax.serv

morris 1万+

Spring mvc ContextLoaderListener 原理解析

对于熟悉Spring MVC功能,首先应从web.xml 开始,在web.xml 文件中我们需要配置一个监听器 ContextLoaderListener,如下。 listener> listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class> listener>

jijianshuai的专栏 3993

springmvc配置文件详解_SpringMVC启动过程详解

通过对SpringMVC启动过程的深入研究,期望掌握Java Web容器启动过程;掌握SpringMVC启动过程;了解SpringMVC的配置文件如何配置,为什么要这样配置;掌握SpringMVC是如何工作的;掌握Spring源码的设计和增强阅读源码的技巧。目录1.Web容器初始化过程2.SpringMVC中web.xml配置3.认识ServletContextListener4...

weixin_29543187的博客 699

SpringMVC ContextLoaderListener初始化过程

在springMVC中容器要启动SpringIOC容器,tomcat是如何初始化IOC容器的呢?我们一般会在web.xml下配置如下: &lt;!-- 配置spring IOC --&gt; &lt;!-- application范围内的参数,存放在ServletContext中 --&gt; &lt;context-param&gt; &lt;param-n...

冷兮Coding 1386

SpringMVC源码分析(一)启动流程分析

SpringMVC启动流程分析

springsdl的博客 452

SpringMVC(一)——【快速入门、执行流程、组件分析】

Spring与Web环境集成 ApplicationContext应用上下文获取方式 应用上下文对象是通过new ClasspathXmIApplicationContext(spring配置文件)方式获取的,但是每次从容器中获得Bean时都要编写new ClasspathXmIApplicationContext(spring配置文件),这样的弊端是配置文件加载多次,应用上下文对象创建多次。 在Web项目中,可以使用ServletContextListener监听Web应用的启动,我们可以在Web应用

龍弟-idea的博客 4510

controller层-浅谈SpringMVC

我们都知道-Tomcat, 是一个web发布容器, 将本地ip暴露出来, 且监听指定端口, 那么一个http请求打进来以后, 是怎样进到服务里并且处理的呢? 1 ContextLoaderListener类 继承了ContextLoader 实现了 ServletContextListener 重点这个监听接口 ServletContextListener public interface ServletContextListener extends EventListener { // 当Servl.

weixin_45657738的博客 576

springmvc流程图_SpringMVC启动过程详解

通过对SpringMVC启动过程的深入研究,期望掌握Java Web容器启动过程;掌握SpringMVC启动过程;了解SpringMVC的配置文件如何配置,为什么要这样配置;掌握SpringMVC是如何工作的;掌握Spring源码的设计和增强阅读源码的技巧。目录1.Web容器初始化过程2.SpringMVC中web.xml配置3.认识ServletContextListener4...

weixin_39820177的博客 419

SpringMVC - 16 - 整合 Spring:ContextLoaderListener / 和 Struts2的对比

建议:还是添加一个 Spring 容器

LawssssCat的博客 386
上一篇: jetty总体设计框架图
下一篇: jetty配置文件详解
fjs_cloud
博客等级 码龄15年 248粉丝 192原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值