CWAC

3. DispatcherServlet 初始化

我与影子孤独终老i 提交于 2020-10-27 18:27:57
看看 handlermapping 和 handleradapter都是怎么初始化的 HttpServletBean public final void init() throws ServletException { ....... //在这里 this.initServletBean(); } servlet的初始化方法 在HttpServletBean 实现了 FrameworkServlet.initServletBean 初始化了springcontext环境 protected final void initServletBean() throws ServletException { ....... try { //初始化WebApplicationContext this.webApplicationContext = this.initWebApplicationContext(); this.initFrameworkServlet(); } catch (RuntimeException | ServletException var4) { this.logger.error("Context initialization failed", var4); throw var4; } . ....... } protected

Spring MVC的初始化

倾然丶 夕夏残阳落幕 提交于 2020-02-28 00:57:17
初始化Spring MVC 项目启动的时候不会对Spring MVC进行初始化,会在接收到第一个请求的时候进行初始化。 首先到了 GenericServlet#init(ServletConfig) 中,然后调用 this#init() 方法,此处的this指向是 DispatcherServlet 对象 public void init(ServletConfig config) throws ServletException { this.config = config; this.init(); } DispatcherServlet 对象执行 init() 方法, DispatcherServlet 对象中的这个方法是继承自 HttpServletBean ,此时会进入到 HttpServletBean#init 中,这里面的重点是 initServletBean() 方法,调用对应的子类进行初始化 public final void init() throws ServletException { // Set bean properties from init parameters. PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this

【Spring】- ContextLoaderListener 工作原理

旧巷老猫 提交于 2019-11-30 06:36:13
ContextLoaderListener:上下文加载器监听器 作用:负责IOC容器的关闭\开启工作 ContextLoaderListener 源码: public class ContextLoaderListener extends ContextLoader implements ServletContextListener{ public ContextLoaderListener() { } public ContextLoaderListener(WebApplicationContext context) { super(context); } @Override public void contextInitialized(ServletContextEvent event) { initWebApplicationContext(event.getServletContext()); } @Override public void contextDestroyed(ServletContextEvent event) { closeWebApplicationContext(event.getServletContext()); ContextCleanupListener.cleanupAttributes(event.getServletContext())