private void initExceptionHandlerAdviceCache() {
    if (getApplicationContext() == null) {
      return;
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Looking for exception mappings: " + getApplicationContext());
    }

    List<ControllerAdviceBean> adviceBeans =
        ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
    AnnotationAwareOrderComparator.sort(adviceBeans);

    for (ControllerAdviceBean adviceBean : adviceBeans) {
      ExceptionHandlerMethodResolver resolver =
          new ExceptionHandlerMethodResolver(adviceBean.getBeanType());
      if (resolver.hasExceptionMappings()) {
        this.exceptionHandlerAdviceCache.put(adviceBean, resolver);
        if (logger.isInfoEnabled()) {
          logger.info("Detected @ExceptionHandler methods in " + adviceBean);
        }
      }
      if (ResponseBodyAdvice.class.isAssignableFrom(adviceBean.getBeanType())) {
        this.responseBodyAdvice.add(adviceBean);
        if (logger.isInfoEnabled()) {
          logger.info("Detected ResponseBodyAdvice implementation in " + adviceBean);
        }
      }
    }
  }
 @Bean
 public JwtAccessTokenConverter jwtTokenEnhancer() {
   JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
   String keyValue = this.resource.getJwt().getKeyValue();
   if (!StringUtils.hasText(keyValue)) {
     try {
       keyValue = getKeyFromServer();
     } catch (ResourceAccessException ex) {
       logger.warn(
           "Failed to fetch token key (you may need to refresh "
               + "when the auth server is back)");
     }
   }
   if (StringUtils.hasText(keyValue) && !keyValue.startsWith("-----BEGIN")) {
     converter.setSigningKey(keyValue);
   }
   if (keyValue != null) {
     converter.setVerifierKey(keyValue);
   }
   AnnotationAwareOrderComparator.sort(this.configurers);
   for (JwtAccessTokenConverterConfigurer configurer : this.configurers) {
     configurer.configure(converter);
   }
   return converter;
 }
 ServletContextInitializerBeans(ListableBeanFactory beanFactory) {
   this.initializers = new LinkedMultiValueMap<Class<?>, ServletContextInitializer>();
   addServletContextInitializerBeans(beanFactory);
   addAdaptableBeans(beanFactory);
   List<ServletContextInitializer> sortedInitializers = new ArrayList<ServletContextInitializer>();
   for (Map.Entry<?, List<ServletContextInitializer>> entry : this.initializers.entrySet()) {
     AnnotationAwareOrderComparator.sort(entry.getValue());
     sortedInitializers.addAll(entry.getValue());
   }
   this.sortedList = Collections.unmodifiableList(sortedInitializers);
 }
  protected void initStrategies(ApplicationContext context) {

    Map<String, HandlerMapping> mappingBeans =
        BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerMapping.class, true, false);

    this.handlerMappings = new ArrayList<>(mappingBeans.values());
    this.handlerMappings.add(new NotFoundHandlerMapping());
    AnnotationAwareOrderComparator.sort(this.handlerMappings);

    Map<String, HandlerAdapter> adapterBeans =
        BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerAdapter.class, true, false);

    this.handlerAdapters = new ArrayList<>(adapterBeans.values());
    AnnotationAwareOrderComparator.sort(this.handlerAdapters);

    Map<String, HandlerResultHandler> beans =
        BeanFactoryUtils.beansOfTypeIncludingAncestors(
            context, HandlerResultHandler.class, true, false);

    this.resultHandlers = new ArrayList<>(beans.values());
    AnnotationAwareOrderComparator.sort(this.resultHandlers);
  }
 @Bean(name = "userInfoRestTemplate")
 public OAuth2RestTemplate userInfoRestTemplate() {
   if (this.details == null) {
     this.details = DEFAULT_RESOURCE_DETAILS;
   }
   OAuth2RestTemplate template = getTemplate();
   template.setInterceptors(
       Arrays.<ClientHttpRequestInterceptor>asList(new AcceptJsonRequestInterceptor()));
   AuthorizationCodeAccessTokenProvider accessTokenProvider =
       new AuthorizationCodeAccessTokenProvider();
   accessTokenProvider.setTokenRequestEnhancer(new AcceptJsonRequestEnhancer());
   template.setAccessTokenProvider(accessTokenProvider);
   AnnotationAwareOrderComparator.sort(this.customizers);
   for (UserInfoRestTemplateCustomizer customizer : this.customizers) {
     customizer.customize(template);
   }
   return template;
 }
 @SuppressWarnings("unchecked")
 private List<ApplicationListener<ApplicationEvent>> getListeners(ConfigurableEnvironment env) {
   String classNames = env.getProperty(PROPERTY_NAME);
   List<ApplicationListener<ApplicationEvent>> listeners =
       new ArrayList<ApplicationListener<ApplicationEvent>>();
   if (StringUtils.hasLength(classNames)) {
     for (String className : StringUtils.commaDelimitedListToSet(classNames)) {
       try {
         Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
         Assert.isAssignable(
             ApplicationListener.class,
             clazz,
             "class [" + className + "] must implement ApplicationListener");
         listeners.add((ApplicationListener<ApplicationEvent>) BeanUtils.instantiateClass(clazz));
       } catch (Exception ex) {
         throw new ApplicationContextException(
             "Failed to load context listener class [" + className + "]", ex);
       }
     }
   }
   AnnotationAwareOrderComparator.sort(listeners);
   return listeners;
 }
  /**
   * Delegate the WebApplicationContext before it is refreshed to any {@link
   * ApplicationContextInitializer} instances specified by the "contextInitializerClasses" servlet
   * init-param.
   *
   * <p>See also {@link #postProcessWebApplicationContext}, which is designed to allow subclasses
   * (as opposed to end-users) to modify the application context, and is called immediately before
   * this method.
   *
   * @param wac the configured WebApplicationContext (not refreshed yet)
   * @see #createWebApplicationContext
   * @see #postProcessWebApplicationContext
   * @see ConfigurableApplicationContext#refresh()
   */
  protected void applyInitializers(ConfigurableApplicationContext wac) {
    String globalClassNames =
        getServletContext().getInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM);
    if (globalClassNames != null) {
      for (String className :
          StringUtils.tokenizeToStringArray(globalClassNames, INIT_PARAM_DELIMITERS)) {
        this.contextInitializers.add(loadInitializer(className, wac));
      }
    }

    if (this.contextInitializerClasses != null) {
      for (String className :
          StringUtils.tokenizeToStringArray(
              this.contextInitializerClasses, INIT_PARAM_DELIMITERS)) {
        this.contextInitializers.add(loadInitializer(className, wac));
      }
    }

    AnnotationAwareOrderComparator.sort(this.contextInitializers);
    for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer :
        this.contextInitializers) {
      initializer.initialize(wac);
    }
  }