采用配置的方式:
![](https://img.haomeiwen.com/i6769743/b708affe372d81dc.png)
这里的所有定义,都会作为bean 存放到WebApplicationContext中
然后在所有的bean解析完之后,作为BeanPostProcesser 的 ApplicationContextAwareProcessor 调用 postProcessBeforeInitialization, 直到最后会调用 AbstractHandlerMapping. detectMappedInterceptors 把所有的interceptors 加载到这个类的adaptedInterceptors中
具体调用链:
![](https://img.haomeiwen.com/i6769743/959a390e7ca2ed4c.png)
真正在 detectMappedInterceptors 方法中,
![](https://img.haomeiwen.com/i6769743/79d2595259f48664.png)
会发现,怎么从所有bean中找到mvc:interceptors 呢: 是通过反射查找 MappedInterceptor 类型
然后mvc:interceptors 会什么是MappedInterceptor呢,定义的是 extends HandlerInterceptorAdapter
这里就是spring的xsd在work了, 具体的mvc:interceptor xsd一部分:
![](https://img.haomeiwen.com/i6769743/3922925f718db510.png)
可以看到,这里就是说明mvc:interceptor 是MappedInterceptor
ok, 问题解决
网友评论