DefaultAnnotationHandlerMapping.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
/**
 * Register all handlers specified in the Portlet mode map for the corresponding modes.
 * @throws org.springframework.beans.BeansException if the handler couldn't be registered
 */
protected void detectHandlers() throws BeansException {
    ApplicationContext context = getApplicationContext();
    String[] beanNames = context.getBeanNamesForType(Object.class);
    for (String beanName : beanNames) {
        Class<?> handlerType = context.getType(beanName);
        RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
        if (mapping != null) {
            // @RequestMapping found at type level
            String[] modeKeys = mapping.value();
            String[] params = mapping.params();
            boolean registerHandlerType = true;
            if (modeKeys.length == 0 || params.length == 0) {
                registerHandlerType = !detectHandlerMethods(handlerType, beanName, mapping);
            }
            if (registerHandlerType) {
                AbstractParameterMappingPredicate predicate = new TypeLevelMappingPredicate(
                        params, mapping.headers(), mapping.method());
                for (String modeKey : modeKeys) {
                    registerHandler(new PortletMode(modeKey), beanName, predicate);
                }
            }
        }
        else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
            detectHandlerMethods(handlerType, beanName, mapping);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号