SpringMVC映射关系是什么时候建立的

1、@EnableWebMvc

2、通过@Import查看

 3、注意这个support类,这个类中有个@Bean注解

 

 4、create方法最终是new出来的对象,这个对象中有个   afterPropertiesSet 显然父类中肯定实现了 InitializingBean ,子类在实例化结束会调用到这个方法

	protected void initHandlerMethods() {
		for (String beanName : getCandidateBeanNames()) {
			if (!beanName.startsWith(SCOPED_TARGET_NAME_PREFIX)) {
				processCandidateBean(beanName);
			}
		}
		handlerMethodsInitialized(getHandlerMethods());
	}

5、最终绑定是在process方法中做的

总结:通过@EnableMVC方式在创建RequstMappingHandleMapping bean之后有个afterProperties 方法进行循环所有的bean来筛选并统计出所有的映射,

  最终映射关系存储在两个map中,一个存url和requstmappinginfo 映射;一个存requestmappinginfo和handleMethod映射。

原文地址:https://www.cnblogs.com/zxg-blog/p/15128603.html