spring注册RestController的关键过程

1.注册RestController时,进入它的反射过程栈信息。

2.registerHandlerMethod时的其中一个变量信息。

3.registerHandlerMethod的具体函数代码

protected void registerHandlerMethod(Object handler, Method method, T mapping) {
        HandlerMethod newHandlerMethod = this.createHandlerMethod(handler, method);
        HandlerMethod oldHandlerMethod = (HandlerMethod)this.handlerMethods.get(mapping);
        if(oldHandlerMethod != null && !oldHandlerMethod.equals(newHandlerMethod)) {
            throw new IllegalStateException("Ambiguous mapping found. Cannot map \'" + newHandlerMethod.getBean() + "\' bean method \n" + newHandlerMethod + "\nto " + mapping + ": There is already \'" + oldHandlerMethod.getBean() + "\' bean method\n" + oldHandlerMethod + " mapped.");
        } else {
            this.handlerMethods.put(mapping, newHandlerMethod);
            if(this.logger.isInfoEnabled()) {
                this.logger.info("Mapped \"" + mapping + "\" onto " + newHandlerMethod);
            }

            Set patterns = this.getMappingPathPatterns(mapping);
            Iterator var7 = patterns.iterator();

            while(var7.hasNext()) {
                String pattern = (String)var7.next();
                if(!this.getPathMatcher().isPattern(pattern)) {
                    this.urlMap.add(pattern, mapping);
                }
            }

        }
    }

3.preInstantiateSingletons的函数是枚举当前的注解定义,把所有注解定义列出来,并进行逐一获取所有注解相关的配置。

public void preInstantiateSingletons() throws BeansException {
        if(this.logger.isDebugEnabled()) {
            this.logger.debug("Pre-instantiating singletons in " + this);
        }

        Map var2 = this.beanDefinitionMap;
        ArrayList beanNames;
        synchronized(this.beanDefinitionMap) {
            beanNames = new ArrayList(this.beanDefinitionNames);
        }

        Iterator var8 = beanNames.iterator();

        while(true) {
            while(true) {
                String beanName;
                RootBeanDefinition bd;
                do {
                    do {
                        do {
                            if(!var8.hasNext()) {
                                return;
                            }

                            beanName = (String)var8.next();
                            bd = this.getMergedLocalBeanDefinition(beanName);
                        } while(bd.isAbstract());
                    } while(!bd.isSingleton());
                } while(bd.isLazyInit());

                if(this.isFactoryBean(beanName)) {
                    final FactoryBean factory = (FactoryBean)this.getBean("&" + beanName);
                    boolean isEagerInit;
                    if(System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
                        isEagerInit = ((Boolean)AccessController.doPrivileged(new PrivilegedAction() {
                            public Boolean run() {
                                return Boolean.valueOf(((SmartFactoryBean)factory).isEagerInit());
                            }
                        }, this.getAccessControlContext())).booleanValue();
                    } else {
                        isEagerInit = factory instanceof SmartFactoryBean && ((SmartFactoryBean)factory).isEagerInit();
                    }

                    if(isEagerInit) {
                        this.getBean(beanName);
                    }
                } else {
                    this.getBean(beanName);
                }
            }
        }
    }