springmvc组件HandleMapping源码分析-AbstractDetectingUrlHandlerMapping

1.AbstractDetectingUrlHandlerMapping继承图

2.概述

 加载容器所有进行url映射处理的bean

3.AbstractDetectingUrlHandlerMapping整个代码用工具翻译后的

https://blog.csdn.net/qq_39482039/article/details/119221041

4.覆盖了AbstractUrlHandlerMapping的initApplicationContext方法,注册在上下文中找到的所有处理程序

	/**
	 * 除了*超类的初始化之外,还调用{@link #detectHandlers()}方法。
	 */
	@Override
	public void initApplicationContext() throws ApplicationContextException {
		//调用父类的initApplicationContext方法
		super.initApplicationContext();
		//注册在上下文中找到的所有处理程序
		detectHandlers();
	}
detectHandlers方法来获取上下文所有bean,留抽象方法给子类做筛选,调用父类方法将url注册成对应的处理程序
	/**
	 * 注册在当前ApplicationContext中找到的所有处理程序。
	 * 处理程序的实际URL确定取决于具体的*
	 * {@link #determineUrlsForHandler(String)}实现。
	 * 不能确定此类URL的*的bean根本不被视为处理程序。
	 * @throws org.springframework.beans.BeansException if the handler couldn't be registered
	 * @see #determineUrlsForHandler(String)
	 */
	protected void detectHandlers() throws BeansException {
		//获取到当前的上下文
		ApplicationContext applicationContext = obtainApplicationContext();
		//detectHandlersInAncestorContexts默认是false,获取所有的bean名称
		String[] beanNames = (this.detectHandlersInAncestorContexts ?
				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, Object.class) :
				applicationContext.getBeanNamesForType(Object.class));

		// 取任何我们可以确定其URL的bean名称。
		for (String beanName : beanNames) {
			//抽象方法子类实现,来筛选对应的bean处理程序
			String[] urls = determineUrlsForHandler(beanName);
			if (!ObjectUtils.isEmpty(urls)) {
				//调用父类的方法,将url注册处理程序
				// 找到的 URL 路径:让我们将其视为处理程序。
				registerHandler(urls, beanName);
			}
		}

		if ((logger.isDebugEnabled() && !getHandlerMap().isEmpty()) || logger.isTraceEnabled()) {
			logger.debug("Detected " + getHandlerMap().size() + " mappings in " + formatMappingName());
		}
	}

 抽象方法留给子类实现,具体处理详见BeanNameUrlHandlerMapping

https://blog.csdn.net/qq_39482039/article/details/119190086

/**
	 * 确定给定处理程序bean的URL。
	 * @param beanName the name of the candidate bean
	 * @return the URLs determined for the bean, or an empty array if none
	 */
	protected abstract String[] determineUrlsForHandler(String beanName);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LouD_dm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值