从入门到放弃(2)-tomcat -spring web.xml

接着从入门到放弃(1)-tomcat -spring web.xml继续对spring启动的探索
上文讲到

ServletContextListener listener =
                (ServletContextListener) instances[i];
                 listener.contextInitialized(event);

调用到我们项目即可找到,idea 快捷键ctrl+shift+n 打开对应的类
在这里插入图片描述
获取类的路径:copy referene : org.springframework.web.context.ContextLoader
在这里插入图片描述
找到 org.springframework.web.context.ContextLoader源码,找到285行打印日志处,可以看到打印了info lever 日志,并且可以找到对应的方法org.springframework.web.context.ContextLoader.initWebApplicationContext(ServletContext servletContext)
在这里插入图片描述
先看下org.springframework.web.context.ContextLoader.initWebApplicationContext(ServletContext servletContext)是从哪里调用进来的,熟悉idea同学可以知道ctrl+鼠标左键可以看到在这个方法在哪里调用
在这里插入图片描述
进入org.springframework.web.context.ContextLoaderListener.contextInitialized(ServletContextEvent event)的112行,可以找到对应的调用位置,详细的contextInitialized(ServletContextEvent event)源码

public void contextInitialized(ServletContextEvent event) {
   
		this.contextLoader = createContextLoader();
		if (this.contextLoader == null) {
   
			this.contextLoader = this;
		}
		this.contextLoader.initWebApplicationContext(event.getServletContext());
	}

因为我三个listen中第一个listen 继承了ContextLoaderListener 并且调用了 super.contextInitialized(event);
在这里插入图片描述
查看当前类的关系,public class ContextLoaderListener extends ContextLoader implements ServletContextListener,继承于ContextLoader 实现于ServletContextListener,这与上篇讲的tomcat启动web.xml 正好合到一起了。并且把event 从tomcat容器成功传递到spring 中
在这里插入图片描述
先看下ContextLoader 加载的内容

private static final Properties defaultStrategies;
static {
   
		// Load default strategy implementations from properties file.
		// This is currently strictly internal and not meant to be customized
		// by application developers.
		try {
   
			ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);
			defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
		}
		catch (IOException ex) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值