首页 > 其他分享 >spring mvc3.2启动分析

spring mvc3.2启动分析

时间:2023-04-25 18:04:30浏览次数:36  
标签:mvc3.2 FrameworkServlet 启动 spring void getServletName ex context logger


1,GenericServlet
    public void init(ServletConfig config) throws ServletException {
	this.config = config;
	this.init();
    }

2,HttpServletBean
	public final void init() throws ServletException {
		if (logger.isDebugEnabled()) {
			logger.debug("Initializing servlet '" + getServletName() + "'");
		}

		// Set bean properties from init parameters.
		try {
			PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
			BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
			ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
			bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
			initBeanWrapper(bw);
			bw.setPropertyValues(pvs, true);
		}
		catch (BeansException ex) {
			logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
			throw ex;
		}

		// Let subclasses do whatever initialization they like.
		initServletBean();
if (logger.isDebugEnabled()) {
			logger.debug("Servlet '" + getServletName() + "' configured successfully");
		}
	}

3,根据xmlWebApplicationContext创建WebApplicationContext
	@Override
	protected final void initServletBean() throws ServletException {
		getServletContext().log("Initializing Spring FrameworkServlet '" + getServletName() + "'");
		if (this.logger.isInfoEnabled()) {
			this.logger.info("FrameworkServlet '" + getServletName() + "': initialization started");
		}
		long startTime = System.currentTimeMillis();

		try {
			this.webApplicationContext = initWebApplicationContext();
			initFrameworkServlet();
		}
		catch (ServletException ex) {
			this.logger.error("Context initialization failed", ex);
			throw ex;
		}
		catch (RuntimeException ex) {
			this.logger.error("Context initialization failed", ex);
			throw ex;
		}

		if (this.logger.isInfoEnabled()) {
			long elapsedTime = System.currentTimeMillis() - startTime;
			this.logger.info("FrameworkServlet '" + getServletName() + "': initialization completed in " +
					elapsedTime + " ms");
		}
	}

4,DispatcherServlet(FrameworkServlet)
	protected void initStrategies(ApplicationContext context) {
		initMultipartResolver(context);
		initLocaleResolver(context);
		initThemeResolver(context);
		initHandlerMappings(context);
		initHandlerAdapters(context);
		initHandlerExceptionResolvers(context);
		initRequestToViewNameTranslator(context);
		initViewResolvers(context);
		initFlashMapManager(context);
	}
5,FrameworkServlet
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
		if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
			// The application context id is still set to its original default value
			// -> assign a more useful id based on available information
			if (this.contextId != null) {
				wac.setId(this.contextId);
			}
			else {
				// Generate default id...
				ServletContext sc = getServletContext();
				if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
					// Servlet <= 2.4: resort to name specified in web.xml, if any.
					String servletContextName = sc.getServletContextName();
					if (servletContextName != null) {
						wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName +
								"." + getServletName());
					}
					else {
						wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
					}
				}
				else {
					// Servlet 2.5's getContextPath available!
					wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
							ObjectUtils.getDisplayString(sc.getContextPath()) + "/" + getServletName());
				}
			}
		}

		wac.setServletContext(getServletContext());
		wac.setServletConfig(getServletConfig());
		wac.setNamespace(getNamespace());
		wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

		// the wac environment's #initPropertySources will be called in any case when
		// the context is refreshed; do it eagerly here to ensure servlet property sources
		// are in place for use in any post-processing or initialization that occurs
		// below prior to #refresh
		ConfigurableEnvironment env = wac.getEnvironment();
		if (env instanceof ConfigurableWebEnvironment) {
			((ConfigurableWebEnvironment)env).initPropertySources(getServletContext(), getServletConfig());
		}

		postProcessWebApplicationContext(wac);

		applyInitializers(wac);

		wac.refresh();
	}
6,退出方法



spring mvc3.2启动分析_Time

标签:mvc3.2,FrameworkServlet,启动,spring,void,getServletName,ex,context,logger
From: https://blog.51cto.com/u_16088628/6224790

相关文章

  • minio安装后启动操作
    下载安装软件可以看文档 http://www.minio.org.cn/docs/minio/linux/index.html安装后:创建一个Minio的systemd服务配置文件:nano/etc/systemd/system/minio.service将以下内容复制到文件中:[Unit]Description=MinIOAfter=network.target[Service]Type=simpleUser=......
  • 小技巧:如何让 Windows 应用程序在 Parallels Desktop 中启动得更快
    经过十多年的发展,ParallelsDesktop在性能方面得到了突飞猛进的提升。但俗话说,“没有最快只有更快。”因此,在这篇文章中,小编将分享您一个小技巧:如何使您的Windows应用程序启动得更快。PD最新版虚拟机永久激活版下载下图显示了视频中的同一台M1MacBookPro和在InteliM......
  • Springboot 在linux后台运行的方法
    1、后台运行程序nohupjava-jar自己的springboot项目.jar>日志文件名.log2>&1&命令详解:nohup:不挂断地运行命令,退出帐户之后继续运行相应的进程。>日志文件名.log:是nohup把command的输出重定向到当前目录的指定的“日志文件名.log”文件中,即输出内容不打印到屏幕上,而......
  • Springboot日期注解失败:while it seems to fit format ‘yyyy-MM-dd‘T‘HH:mm:ss.SSS
    提交字符串到后台映射为Date类型可以加上@DateTimeFormat(pattern="yyyy-MM-ddHH:mm:ss")注解,但是报错了!前端提交字符串到后台,出现如下错误:whileitseemstofitformat'yyyy-MM-dd'T'HH:mm:ss.SSSZ',parsingfails(leniency?null))错误的大致意思就是字符串映射到Da......
  • Advanced Installer设置安装最后一步启动软件
    左侧用户界面中选择对话框-ExitDialog在完成操作项中勾选“安装结束时启动应用程序”,在弹出的对话框中选择需要启动的exe文件 ......
  • 使用Dockerfile部署springboot打包jar包
    1、docker下载JDK1.8镜像dockerpulljava:82、编写Dockerfile文件#依赖的父镜像FROMjava:8#作者MAINTAINERdocker-admin#jar包添加到镜像中ADDxxl-job-admin-2.1.2.jarxxl-job-admin.jar#容器暴露的端口即jar程序在容器中运行的端口EXPOSE8080#容器启动之后......
  • java面试题--springboot
    一、SpringBoot自动装配原理是什么?@SpringBootApplication@EnableAutoConfigration\@SpringBootConfigration\@ComponentScan@AutoConfigrationPackage\@ImportMETA-INF\spring.factories二、说一下@Configuration中的属性proxyBeanMethods的作用?首先,引入两个概念:Full全......
  • SpringSecurity从入门到精通:授权基本流程&设置资源所需权限&封装权限信息
    授权基本流程在SpringSecurity中,会使用默认的FilterSecurityInterceptor来进行权限校验,在FilterSecurityInterceptor中会从SecurityContextHilder获取其中的Authentication,然后获取其中的权限信息,当前用户是否拥有访问当前资源所需的权限所以我们在项目中只需要把当前登......
  • oracle 启动 关闭
    shutdownimmediate:阻止任何用户新的连接,同时限制当前连接用户开始新的事务。如果已连接用户有未完成的事务,则数据库系统不会等待他们完成,而是直接把当前未递交的事务回退 startupopen:startup的默认参数就是open,打开数据库,允许数据库的访问,当前实例控制文件中所描述的所有文......
  • SpringBoot 使用 Sa-Token 完成权限认证
    一、设计思路所谓权限认证,核心逻辑就是判断一个账号是否拥有指定权限:有,就让你通过。没有?那么禁止访问!深入到底层数据中,就是每个账号都会拥有一个权限码集合,框架来校验这个集合中是否包含指定的权限码。例如:当前账号拥有权限码集合["user-add","user-delete","user-get"]......