@Test
 public void prototypeCreationIsFastEnough() {
   if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
     // Skip this test: Trace logging blows the time limit.
     return;
   }
   GenericApplicationContext ac = new GenericApplicationContext();
   RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
   rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
   rbd.getConstructorArgumentValues().addGenericArgumentValue("#{systemProperties.name}");
   rbd.getPropertyValues().add("country", "#{systemProperties.country}");
   ac.registerBeanDefinition("test", rbd);
   ac.refresh();
   StopWatch sw = new StopWatch();
   sw.start("prototype");
   System.getProperties().put("name", "juergen");
   System.getProperties().put("country", "UK");
   try {
     for (int i = 0; i < 100000; i++) {
       TestBean tb = (TestBean) ac.getBean("test");
       assertEquals("juergen", tb.getName());
       assertEquals("UK", tb.getCountry());
     }
     sw.stop();
   } finally {
     System.getProperties().remove("country");
     System.getProperties().remove("name");
   }
   assertTrue(
       "Prototype creation took too long: " + sw.getTotalTimeMillis(),
       sw.getTotalTimeMillis() < 6000);
 }
  @Test
  public void resolveChannelNameFromContext() {
    StaticApplicationContext context = new StaticApplicationContext();
    RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
    routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
    routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
    context.registerBeanDefinition("router", routerBeanDefinition);
    context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
    context.registerBeanDefinition("newChannel", new RootBeanDefinition(QueueChannel.class));
    context.refresh();
    MessageHandler handler = (MessageHandler) context.getBean("router");
    Message<?> message =
        MessageBuilder.withPayload("test").setHeader("testHeaderName", "testChannel").build();
    handler.handleMessage(message);
    QueueChannel channel = (QueueChannel) context.getBean("testChannel");
    Message<?> result = channel.receive(1000);
    assertNotNull(result);
    assertSame(message, result);

    // validate dynamics
    HeaderValueRouter router = (HeaderValueRouter) context.getBean("router");
    router.setChannelMapping("testChannel", "newChannel");
    router.handleMessage(message);
    QueueChannel newChannel = (QueueChannel) context.getBean("newChannel");
    result = newChannel.receive(10);
    assertNotNull(result);

    router.removeChannelMapping("testChannel");
    router.handleMessage(message);
    result = channel.receive(1000);
    assertNotNull(result);
    assertSame(message, result);
    context.close();
  }
 @Test
 public void dynamicChannelCache() {
   StaticApplicationContext context = new StaticApplicationContext();
   RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
   routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
   routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
   routerBeanDefinition.getPropertyValues().addPropertyValue("dynamicChannelLimit", "2");
   context.registerBeanDefinition("router", routerBeanDefinition);
   context.registerBeanDefinition("channel1", new RootBeanDefinition(QueueChannel.class));
   context.registerBeanDefinition("channel2", new RootBeanDefinition(QueueChannel.class));
   context.registerBeanDefinition("channel3", new RootBeanDefinition(QueueChannel.class));
   context.refresh();
   MessageHandler handler = (MessageHandler) context.getBean("router");
   String channels = "channel1, channel2, channel1, channel3";
   Message<?> message =
       MessageBuilder.withPayload("test").setHeader("testHeaderName", channels).build();
   handler.handleMessage(message);
   QueueChannel channel1 = (QueueChannel) context.getBean("channel1");
   QueueChannel channel2 = (QueueChannel) context.getBean("channel2");
   QueueChannel channel3 = (QueueChannel) context.getBean("channel3");
   assertThat(channel1.getQueueSize(), equalTo(2));
   assertThat(channel2.getQueueSize(), equalTo(1));
   assertThat(channel3.getQueueSize(), equalTo(1));
   assertThat(
       context.getBean(HeaderValueRouter.class).getDynamicChannelNames(),
       contains("channel1", "channel3"));
   context.close();
 }
 @Test
 public void resolveMultipleChannelsWithCommaDelimitedString() {
   StaticApplicationContext context = new StaticApplicationContext();
   RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
   routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
   routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
   context.registerBeanDefinition("router", routerBeanDefinition);
   context.registerBeanDefinition("channel1", new RootBeanDefinition(QueueChannel.class));
   context.registerBeanDefinition("channel2", new RootBeanDefinition(QueueChannel.class));
   context.refresh();
   MessageHandler handler = (MessageHandler) context.getBean("router");
   String channels = "channel1, channel2";
   Message<?> message =
       MessageBuilder.withPayload("test").setHeader("testHeaderName", channels).build();
   handler.handleMessage(message);
   QueueChannel channel1 = (QueueChannel) context.getBean("channel1");
   QueueChannel channel2 = (QueueChannel) context.getBean("channel2");
   Message<?> result1 = channel1.receive(1000);
   Message<?> result2 = channel2.receive(1000);
   assertNotNull(result1);
   assertNotNull(result2);
   assertSame(message, result1);
   assertSame(message, result2);
   context.close();
 }
 @Test
 @SuppressWarnings({"unchecked", "rawtypes"})
 public void resolveChannelNameFromMapAndCustomeResolver() {
   final StaticApplicationContext context = new StaticApplicationContext();
   ManagedMap channelMappings = new ManagedMap();
   channelMappings.put("testKey", "testChannel");
   RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
   routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
   routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
   routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
   routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
   routerBeanDefinition
       .getPropertyValues()
       .addPropertyValue(
           "channelResolver",
           (DestinationResolver<MessageChannel>)
               channelName -> context.getBean("anotherChannel", MessageChannel.class));
   context.registerBeanDefinition("router", routerBeanDefinition);
   context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
   context.registerBeanDefinition("anotherChannel", new RootBeanDefinition(QueueChannel.class));
   context.refresh();
   MessageHandler handler = (MessageHandler) context.getBean("router");
   Message<?> message =
       MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
   handler.handleMessage(message);
   QueueChannel channel = (QueueChannel) context.getBean("anotherChannel");
   Message<?> result = channel.receive(1000);
   assertNotNull(result);
   assertSame(message, result);
   context.close();
 }
  public static RootBeanDefinition createExpressionDefinitionFromValueOrExpression(
      String valueElementName,
      String expressionElementName,
      ParserContext parserContext,
      Element element,
      boolean oneRequired) {

    Assert.hasText(valueElementName, "'valueElementName' must not be empty");
    Assert.hasText(expressionElementName, "'expressionElementName' must no be empty");

    String valueElementValue = element.getAttribute(valueElementName);
    String expressionElementValue = element.getAttribute(expressionElementName);

    boolean hasAttributeValue = StringUtils.hasText(valueElementValue);
    boolean hasAttributeExpression = StringUtils.hasText(expressionElementValue);

    if (hasAttributeValue && hasAttributeExpression) {
      parserContext
          .getReaderContext()
          .error(
              "Only one of '"
                  + valueElementName
                  + "' or '"
                  + expressionElementName
                  + "' is allowed",
              element);
    }

    if (oneRequired && (!hasAttributeValue && !hasAttributeExpression)) {
      parserContext
          .getReaderContext()
          .error(
              "One of '" + valueElementName + "' or '" + expressionElementName + "' is required",
              element);
    }
    RootBeanDefinition expressionDef = null;
    if (hasAttributeValue) {
      expressionDef = new RootBeanDefinition(LiteralExpression.class);
      expressionDef.getConstructorArgumentValues().addGenericArgumentValue(valueElementValue);
    } else if (hasAttributeExpression) {
      expressionDef = new RootBeanDefinition(ExpressionFactoryBean.class);
      expressionDef.getConstructorArgumentValues().addGenericArgumentValue(expressionElementValue);
    }
    return expressionDef;
  }
  @Test
  public void listenerAndBroadcasterWithCircularReference() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("broadcaster", new RootBeanDefinition(BeanThatBroadcasts.class));
    RootBeanDefinition listenerDef = new RootBeanDefinition(BeanThatListens.class);
    listenerDef
        .getConstructorArgumentValues()
        .addGenericArgumentValue(new RuntimeBeanReference("broadcaster"));
    context.registerBeanDefinition("listener", listenerDef);
    context.refresh();

    BeanThatBroadcasts broadcaster = context.getBean("broadcaster", BeanThatBroadcasts.class);
    context.publishEvent(new MyEvent(context));
    assertEquals("The event was not received by the listener", 2, broadcaster.receivedCount);

    context.close();
  }
 @Test
 public void channelAsHeaderValue() {
   StaticApplicationContext context = new StaticApplicationContext();
   RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
   routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
   routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
   context.registerBeanDefinition("router", routerBeanDefinition);
   context.refresh();
   MessageHandler handler = (MessageHandler) context.getBean("router");
   QueueChannel testChannel = new QueueChannel();
   Message<?> message =
       MessageBuilder.withPayload("test").setHeader("testHeaderName", testChannel).build();
   handler.handleMessage(message);
   Message<?> result = testChannel.receive(1000);
   assertNotNull(result);
   assertSame(message, result);
   context.close();
 }
  @Override
  protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder =
        BeanDefinitionBuilder.genericBeanDefinition(RedisCollectionPopulatingMessageHandler.class);

    String redisTemplateRef = element.getAttribute("redis-template");
    String connectionFactory = element.getAttribute("connection-factory");
    if (StringUtils.hasText(redisTemplateRef) && StringUtils.hasText(connectionFactory)) {
      parserContext
          .getReaderContext()
          .error("Only one of 'redis-template' or 'connection-factory'" + " is allowed", element);
    }

    if (StringUtils.hasText(redisTemplateRef)) {
      builder.addConstructorArgReference(redisTemplateRef);
    } else {
      if (!StringUtils.hasText(connectionFactory)) {
        connectionFactory = "redisConnectionFactory";
      }
      builder.addConstructorArgReference(connectionFactory);
    }

    boolean atLeastOneRequired = false;
    RootBeanDefinition expressionDef =
        IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression(
            "key", "key-expression", parserContext, element, atLeastOneRequired);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "collection-type");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        builder, element, "extract-payload-elements");

    if (expressionDef != null) {
      builder.addConstructorArgValue(expressionDef);
    }

    String mapKeyExpression = element.getAttribute("map-key-expression");
    if (StringUtils.hasText(mapKeyExpression)) {
      RootBeanDefinition mapKeyExpressionDef = new RootBeanDefinition(ExpressionFactoryBean.class);
      mapKeyExpressionDef.getConstructorArgumentValues().addGenericArgumentValue(mapKeyExpression);
      builder.addPropertyValue("mapKeyExpression", mapKeyExpressionDef);
    }

    return builder.getBeanDefinition();
  }
 private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
   ManagedList<Object> result = new ManagedList<Object>();
   for (Object object : list) {
     if (object instanceof BeanDefinitionHolder) {
       BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
       String className = beanDef.getBeanDefinition().getBeanClassName();
       Class<?> clazz =
           ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
       if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
         RootBeanDefinition adapter =
             new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
         adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
         result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
         continue;
       }
     }
     result.add(object);
   }
   return result;
 }
  @Test
  public void listenersInApplicationContext() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class));
    RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class);
    listener2
        .getConstructorArgumentValues()
        .addGenericArgumentValue(new RuntimeBeanReference("listener1"));
    listener2.setLazyInit(true);
    context.registerBeanDefinition("listener2", listener2);
    context.refresh();
    assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));

    MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
    MyOtherEvent event1 = new MyOtherEvent(context);
    context.publishEvent(event1);
    assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
    MyEvent event2 = new MyEvent(context);
    context.publishEvent(event2);
    assertTrue(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
    MyEvent event3 = new MyEvent(context);
    context.publishEvent(event3);
    MyOtherEvent event4 = new MyOtherEvent(context);
    context.publishEvent(event4);
    assertTrue(listener1.seenEvents.contains(event1));
    assertTrue(listener1.seenEvents.contains(event2));
    assertTrue(listener1.seenEvents.contains(event3));
    assertTrue(listener1.seenEvents.contains(event4));

    listener1.seenEvents.clear();
    context.publishEvent(event1);
    context.publishEvent(event2);
    context.publishEvent(event3);
    context.publishEvent(event4);
    assertTrue(listener1.seenEvents.contains(event1));
    assertTrue(listener1.seenEvents.contains(event2));
    assertTrue(listener1.seenEvents.contains(event3));
    assertTrue(listener1.seenEvents.contains(event4));

    context.close();
  }
  private ManagedList<?> getMessageConverters(
      Element element, Object source, ParserContext parserContext) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> messageConverters = new ManagedList<Object>();
    if (convertersElement != null) {
      messageConverters.setSource(source);
      for (Element beanElement :
          DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
        Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
        messageConverters.add(object);
      }
    }

    if (convertersElement == null
        || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
      messageConverters.setSource(source);
      messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));

      RootBeanDefinition stringConverterDef =
          createConverterDefinition(StringHttpMessageConverter.class, source);
      stringConverterDef.getPropertyValues().add("writeAcceptCharset", false);
      messageConverters.add(stringConverterDef);

      messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source));
      messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source));
      messageConverters.add(
          createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source));

      if (romePresent) {
        messageConverters.add(
            createConverterDefinition(AtomFeedHttpMessageConverter.class, source));
        messageConverters.add(
            createConverterDefinition(RssChannelHttpMessageConverter.class, source));
      }

      if (jackson2XmlPresent) {
        RootBeanDefinition jacksonConverterDef =
            createConverterDefinition(MappingJackson2XmlHttpMessageConverter.class, source);
        GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
        jacksonFactoryDef.getPropertyValues().add("createXmlMapper", true);
        jacksonConverterDef
            .getConstructorArgumentValues()
            .addIndexedArgumentValue(0, jacksonFactoryDef);
        messageConverters.add(jacksonConverterDef);
      } else if (jaxb2Present) {
        messageConverters.add(
            createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source));
      }

      if (jackson2Present) {
        RootBeanDefinition jacksonConverterDef =
            createConverterDefinition(MappingJackson2HttpMessageConverter.class, source);
        GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
        jacksonConverterDef
            .getConstructorArgumentValues()
            .addIndexedArgumentValue(0, jacksonFactoryDef);
        messageConverters.add(jacksonConverterDef);
      } else if (gsonPresent) {
        messageConverters.add(createConverterDefinition(GsonHttpMessageConverter.class, source));
      }
    }
    return messageConverters;
  }
  @Override
  public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    XmlReaderContext readerContext = parserContext.getReaderContext();

    CompositeComponentDefinition compDefinition =
        new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);

    RuntimeBeanReference contentNegotiationManager =
        getContentNegotiationManager(element, source, parserContext);

    RootBeanDefinition handlerMappingDef =
        new RootBeanDefinition(RequestMappingHandlerMapping.class);
    handlerMappingDef.setSource(source);
    handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    handlerMappingDef.getPropertyValues().add("order", 0);
    handlerMappingDef
        .getPropertyValues()
        .add("contentNegotiationManager", contentNegotiationManager);

    if (element.hasAttribute("enable-matrix-variables")) {
      Boolean enableMatrixVariables =
          Boolean.valueOf(element.getAttribute("enable-matrix-variables"));
      handlerMappingDef.getPropertyValues().add("removeSemicolonContent", !enableMatrixVariables);
    } else if (element.hasAttribute("enableMatrixVariables")) {
      Boolean enableMatrixVariables =
          Boolean.valueOf(element.getAttribute("enableMatrixVariables"));
      handlerMappingDef.getPropertyValues().add("removeSemicolonContent", !enableMatrixVariables);
    }

    configurePathMatchingProperties(handlerMappingDef, element, parserContext);
    readerContext
        .getRegistry()
        .registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, handlerMappingDef);

    RuntimeBeanReference corsConfigurationsRef =
        MvcNamespaceUtils.registerCorsConfigurations(null, parserContext, source);
    handlerMappingDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

    RuntimeBeanReference conversionService = getConversionService(element, source, parserContext);
    RuntimeBeanReference validator = getValidator(element, source, parserContext);
    RuntimeBeanReference messageCodesResolver = getMessageCodesResolver(element);

    RootBeanDefinition bindingDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
    bindingDef.setSource(source);
    bindingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    bindingDef.getPropertyValues().add("conversionService", conversionService);
    bindingDef.getPropertyValues().add("validator", validator);
    bindingDef.getPropertyValues().add("messageCodesResolver", messageCodesResolver);

    ManagedList<?> messageConverters = getMessageConverters(element, source, parserContext);
    ManagedList<?> argumentResolvers = getArgumentResolvers(element, parserContext);
    ManagedList<?> returnValueHandlers = getReturnValueHandlers(element, parserContext);
    String asyncTimeout = getAsyncTimeout(element);
    RuntimeBeanReference asyncExecutor = getAsyncExecutor(element);
    ManagedList<?> callableInterceptors = getCallableInterceptors(element, source, parserContext);
    ManagedList<?> deferredResultInterceptors =
        getDeferredResultInterceptors(element, source, parserContext);

    RootBeanDefinition handlerAdapterDef =
        new RootBeanDefinition(RequestMappingHandlerAdapter.class);
    handlerAdapterDef.setSource(source);
    handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    handlerAdapterDef
        .getPropertyValues()
        .add("contentNegotiationManager", contentNegotiationManager);
    handlerAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
    handlerAdapterDef.getPropertyValues().add("messageConverters", messageConverters);
    addRequestBodyAdvice(handlerAdapterDef);
    addResponseBodyAdvice(handlerAdapterDef);

    if (element.hasAttribute("ignore-default-model-on-redirect")) {
      Boolean ignoreDefaultModel =
          Boolean.valueOf(element.getAttribute("ignore-default-model-on-redirect"));
      handlerAdapterDef.getPropertyValues().add("ignoreDefaultModelOnRedirect", ignoreDefaultModel);
    } else if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
      // "ignoreDefaultModelOnRedirect" spelling is deprecated
      Boolean ignoreDefaultModel =
          Boolean.valueOf(element.getAttribute("ignoreDefaultModelOnRedirect"));
      handlerAdapterDef.getPropertyValues().add("ignoreDefaultModelOnRedirect", ignoreDefaultModel);
    }

    if (argumentResolvers != null) {
      handlerAdapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
    }
    if (returnValueHandlers != null) {
      handlerAdapterDef.getPropertyValues().add("customReturnValueHandlers", returnValueHandlers);
    }
    if (asyncTimeout != null) {
      handlerAdapterDef.getPropertyValues().add("asyncRequestTimeout", asyncTimeout);
    }
    if (asyncExecutor != null) {
      handlerAdapterDef.getPropertyValues().add("taskExecutor", asyncExecutor);
    }

    handlerAdapterDef.getPropertyValues().add("callableInterceptors", callableInterceptors);
    handlerAdapterDef
        .getPropertyValues()
        .add("deferredResultInterceptors", deferredResultInterceptors);
    readerContext
        .getRegistry()
        .registerBeanDefinition(HANDLER_ADAPTER_BEAN_NAME, handlerAdapterDef);

    String uriCompContribName = MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME;
    RootBeanDefinition uriCompContribDef =
        new RootBeanDefinition(CompositeUriComponentsContributorFactoryBean.class);
    uriCompContribDef.setSource(source);
    uriCompContribDef.getPropertyValues().addPropertyValue("handlerAdapter", handlerAdapterDef);
    uriCompContribDef.getPropertyValues().addPropertyValue("conversionService", conversionService);
    readerContext.getRegistry().registerBeanDefinition(uriCompContribName, uriCompContribDef);

    RootBeanDefinition csInterceptorDef =
        new RootBeanDefinition(ConversionServiceExposingInterceptor.class);
    csInterceptorDef.setSource(source);
    csInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, conversionService);
    RootBeanDefinition mappedCsInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
    mappedCsInterceptorDef.setSource(source);
    mappedCsInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    mappedCsInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
    mappedCsInterceptorDef
        .getConstructorArgumentValues()
        .addIndexedArgumentValue(1, csInterceptorDef);
    String mappedInterceptorName = readerContext.registerWithGeneratedName(mappedCsInterceptorDef);

    RootBeanDefinition exceptionHandlerExceptionResolver =
        new RootBeanDefinition(ExceptionHandlerExceptionResolver.class);
    exceptionHandlerExceptionResolver.setSource(source);
    exceptionHandlerExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    exceptionHandlerExceptionResolver
        .getPropertyValues()
        .add("contentNegotiationManager", contentNegotiationManager);
    exceptionHandlerExceptionResolver
        .getPropertyValues()
        .add("messageConverters", messageConverters);
    exceptionHandlerExceptionResolver.getPropertyValues().add("order", 0);
    addResponseBodyAdvice(exceptionHandlerExceptionResolver);

    String methodExceptionResolverName =
        readerContext.registerWithGeneratedName(exceptionHandlerExceptionResolver);

    RootBeanDefinition responseStatusExceptionResolver =
        new RootBeanDefinition(ResponseStatusExceptionResolver.class);
    responseStatusExceptionResolver.setSource(source);
    responseStatusExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    responseStatusExceptionResolver.getPropertyValues().add("order", 1);
    String responseStatusExceptionResolverName =
        readerContext.registerWithGeneratedName(responseStatusExceptionResolver);

    RootBeanDefinition defaultExceptionResolver =
        new RootBeanDefinition(DefaultHandlerExceptionResolver.class);
    defaultExceptionResolver.setSource(source);
    defaultExceptionResolver.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    defaultExceptionResolver.getPropertyValues().add("order", 2);
    String defaultExceptionResolverName =
        readerContext.registerWithGeneratedName(defaultExceptionResolver);

    parserContext.registerComponent(
        new BeanComponentDefinition(handlerMappingDef, HANDLER_MAPPING_BEAN_NAME));
    parserContext.registerComponent(
        new BeanComponentDefinition(handlerAdapterDef, HANDLER_ADAPTER_BEAN_NAME));
    parserContext.registerComponent(
        new BeanComponentDefinition(uriCompContribDef, uriCompContribName));
    parserContext.registerComponent(
        new BeanComponentDefinition(
            exceptionHandlerExceptionResolver, methodExceptionResolverName));
    parserContext.registerComponent(
        new BeanComponentDefinition(
            responseStatusExceptionResolver, responseStatusExceptionResolverName));
    parserContext.registerComponent(
        new BeanComponentDefinition(defaultExceptionResolver, defaultExceptionResolverName));
    parserContext.registerComponent(
        new BeanComponentDefinition(mappedCsInterceptorDef, mappedInterceptorName));

    // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
    MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

    parserContext.popAndRegisterContainingComponent();

    return null;
  }