@Override
 protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
   super.doParse(element, ctx, bean);
   bean.setLazyInit(false);
   // put the bean id into the property map
   Map<String, Object> map = getPropertyMap(bean, true);
   map.put("beanId", resolveId(element, bean.getBeanDefinition(), ctx));
   // set the bean scope to be prototype, then we can get a new instance in each look up
   bean.setScope(BeanDefinition.SCOPE_PROTOTYPE);
 }
  /**
   * Build the POJO with the username and password.
   *
   * @param element the HTTPMetadataProvider parser.
   * @return the bean definition with the username and password.
   */
  private BeanDefinition buildBasicCredentials(Element element) {
    BeanDefinitionBuilder builder =
        BeanDefinitionBuilder.genericBeanDefinition(UsernamePasswordCredentials.class);

    builder.setLazyInit(true);

    builder.addConstructorArgValue(
        StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_USER)));
    builder.addConstructorArgValue(
        StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_PASSWORD)));

    return builder.getBeanDefinition();
  }
 /** 将 JobRunner 生成Bean放入spring容器中管理 采用原型 scope, 所以可以在JobRunner中使用@Autowired */
 private void registerRunnerBeanDefinition() {
   DefaultListableBeanFactory beanFactory =
       (DefaultListableBeanFactory)
           ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
   jobRunnerBeanName = "LTS_".concat(jobRunnerClass.getSimpleName());
   if (!beanFactory.containsBean(jobRunnerBeanName)) {
     BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(jobRunnerClass);
     if (jobRunnerClass == JobDispatcher.class) {
       builder.setScope(BeanDefinition.SCOPE_SINGLETON);
       builder.setLazyInit(false);
       builder.getBeanDefinition().getPropertyValues().addPropertyValue("shardField", shardField);
     } else {
       builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
     }
     beanFactory.registerBeanDefinition(jobRunnerBeanName, builder.getBeanDefinition());
   }
 }
  // Checkstyle: CyclomaticComplexity OFF
  // Checkstyle: MethodLength OFF
  private BeanDefinition buildHttpClient(
      Element element, ParserContext parserContext, boolean haveTLSTrustEngine) {
    String caching = DEFAULT_CACHING;
    if (element.hasAttributeNS(null, "httpCaching")) {
      caching = StringSupport.trimOrNull(element.getAttributeNS(null, "httpCaching"));
    }

    BeanDefinitionBuilder clientBuilder = null;
    switch (caching) {
      case "none":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpClientFactoryBean.class);
        break;
      case "file":
        clientBuilder =
            BeanDefinitionBuilder.genericBeanDefinition(FileCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpCacheDirectory")) {
          clientBuilder.addPropertyValue(
              "cacheDirectory",
              StringSupport.trimOrNull(element.getAttributeNS(null, "httpCacheDirectory")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
          clientBuilder.addPropertyValue(
              "maxCacheEntries",
              StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
          clientBuilder.addPropertyValue(
              "maxCacheEntrySize",
              StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
      case "memory":
        clientBuilder =
            BeanDefinitionBuilder.genericBeanDefinition(InMemoryCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
          clientBuilder.addPropertyValue(
              "maxCacheEntries",
              StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
          clientBuilder.addPropertyValue(
              "maxCacheEntrySize",
              StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
      default:
        throw new BeanDefinitionParsingException(
            new Problem(
                String.format("Caching value '%s' is unsupported", caching),
                new Location(parserContext.getReaderContext().getResource())));
    }

    clientBuilder.setLazyInit(true);

    if (element.hasAttributeNS(null, "requestTimeout")) {
      clientBuilder.addPropertyValue(
          "connectionTimeout",
          StringSupport.trimOrNull(element.getAttributeNS(null, "requestTimeout")));
    }

    if (haveTLSTrustEngine) {
      clientBuilder.addPropertyValue(
          "tLSSocketFactory",
          new SecurityEnhancedTLSSocketFactory(
              HttpClientSupport.buildNoTrustTLSSocketFactory(), new StrictHostnameVerifier()));
    }

    if (element.hasAttributeNS(null, "disregardTLSCertificate")) {
      clientBuilder.addPropertyValue(
          "connectionDisregardTLSCertificate",
          StringSupport.trimOrNull(element.getAttributeNS(null, "disregardTLSCertificate")));
    } else if (element.hasAttributeNS(null, "disregardSslCertificate")) {
      log.warn("disregardSslCertificate is deprecated, please switch to disregardTLSCertificate");
      clientBuilder.addPropertyValue(
          "connectionDisregardTLSCertificate",
          StringSupport.trimOrNull(element.getAttributeNS(null, "disregardSslCertificate")));
    }

    if (element.hasAttributeNS(null, "proxyHost")) {
      clientBuilder.addPropertyValue(
          "connectionProxyHost",
          StringSupport.trimOrNull(element.getAttributeNS(null, "proxyHost")));
    }

    if (element.hasAttributeNS(null, "proxyPort")) {
      clientBuilder.addPropertyValue(
          "connectionProxyPort",
          StringSupport.trimOrNull(element.getAttributeNS(null, "proxyPort")));
    }

    if (element.hasAttributeNS(null, "proxyUser")) {
      clientBuilder.addPropertyValue(
          "connectionProxyUsername",
          StringSupport.trimOrNull(element.getAttributeNS(null, "proxyUser")));
    }

    if (element.hasAttributeNS(null, "proxyPassword")) {
      clientBuilder.addPropertyValue(
          "connectionProxyPassword", element.getAttributeNS(null, "proxyPassword"));
    }

    return clientBuilder.getBeanDefinition();
  }
  @Override
  protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    boolean isAbstract = false;
    boolean publish = true;
    NamedNodeMap atts = element.getAttributes();
    String bus = element.getAttribute("bus");
    if (StringUtils.isEmpty(bus)) {
      addBusWiringAttribute(bean, BusWiringType.CONSTRUCTOR);
    } else {
      bean.addConstructorArgReference(bus);
    }
    for (int i = 0; i < atts.getLength(); i++) {
      Attr node = (Attr) atts.item(i);
      String val = node.getValue();
      String pre = node.getPrefix();
      String name = node.getLocalName();

      if ("createdFromAPI".equals(name)) {
        bean.setAbstract(true);
        isAbstract = true;
      } else if (isAttribute(pre, name) && !"publish".equals(name) && !"bus".equals(name)) {
        if ("endpointName".equals(name) || "serviceName".equals(name)) {
          QName q = parseQName(element, val);
          bean.addPropertyValue(name, q);
        } else if ("depends-on".equals(name)) {
          bean.addDependsOn(val);
        } else if (IMPLEMENTOR.equals(name)) {
          loadImplementor(bean, val);
        } else if (!"name".equals(name)) {
          mapToProperty(bean, name, val);
        }
      } else if ("abstract".equals(name)) {
        bean.setAbstract(true);
        isAbstract = true;
      } else if ("publish".equals(name)) {
        publish = "true".equals(val);
      }
    }

    Element elem = DOMUtils.getFirstElement(element);
    while (elem != null) {
      String name = elem.getLocalName();
      if ("properties".equals(name)) {
        Map<?, ?> map = ctx.getDelegate().parseMapElement(elem, bean.getBeanDefinition());
        bean.addPropertyValue("properties", map);
      } else if ("binding".equals(name)) {
        setFirstChildAsProperty(elem, ctx, bean, "bindingConfig");
      } else if ("inInterceptors".equals(name)
          || "inFaultInterceptors".equals(name)
          || "outInterceptors".equals(name)
          || "outFaultInterceptors".equals(name)
          || "features".equals(name)
          || "schemaLocations".equals(name)
          || "handlers".equals(name)) {
        List<?> list = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
        bean.addPropertyValue(name, list);
      } else if (IMPLEMENTOR.equals(name)) {
        ctx.getDelegate().parseConstructorArgElement(elem, bean.getBeanDefinition());
      } else {
        setFirstChildAsProperty(elem, ctx, bean, name);
      }
      elem = DOMUtils.getNextElement(elem);
    }
    if (!isAbstract) {
      if (publish) {
        bean.setInitMethodName("publish");
      }
      bean.setDestroyMethodName("stop");
    }
    // We don't want to delay the registration of our Server
    bean.setLazyInit(false);
  }