springboot mappings 注册逻辑
原文中文,约6300字,阅读约需15分钟。
📝
内容提要
RequestMappingHandlerMapping类继承关系和注册过程。实现InitializingBean接口,通过afterPropertiesSet方法设置属性。调用initHandlerMethods方法遍历候选bean并处理。detectHandlerMethods方法找到有Mapping注解的方法并注册。register方法进行真正的注册逻辑。
🎯
关键要点
-
RequestMappingHandlerMapping类实现了InitializingBean接口,允许在bean初始化后设置属性。
-
afterPropertiesSet方法调用父类的afterPropertiesSet,初始化HandlerMethod。
-
initHandlerMethods方法遍历候选bean并处理,调用processCandidateBean方法。
-
processCandidateBean方法获取beanType并判断其是否为Handler。
-
isHandler方法通过检查Controller或RequestMapping注解来判断beanType。
-
detectHandlerMethods方法找到有Mapping注解的方法并进行注册。
-
getMappingForMethod方法用于获取方法的RequestMapping信息。
-
registerHandlerMethod方法将映射信息存储到mappingRegistry中。
-
register方法实现了真正的注册逻辑,包括存储映射信息和处理CORS配置。
🏷️