/** 将 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());
   }
 }
 @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);
 }
 public BeanDefinition parse(Element element, ParserContext parserContext) {
   BeanDefinitionBuilder builder =
       BeanDefinitionBuilder.rootBeanDefinition(ConsumerMessageSource.class.getName());
   builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
   parseConfigRef(element, builder);
   parseProperty(builder, element, "topic", "topic");
   BeanDefinition definition = builder.getBeanDefinition();
   setNoRecurseOnDefinition(definition);
   attachSourceDefinition(parserContext, definition);
   return definition;
 }
  /* (non-Javadoc)
   * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.support.BeanDefinitionBuilder)
   */
  @Override
  protected void doParse(Element element, BeanDefinitionBuilder builder) {
    builder.setScope("prototype");
    String path = element.getAttribute("path");
    builder.addConstructorArgValue(path);

    String encoding = element.getAttribute("encoding");
    if (StringUtils.hasText(encoding)) {
      builder.addConstructorArgValue(encoding);
    }
  }
 public BeanDefinition parse(Element element, ParserContext parserContext) {
   parseConfigName(element);
   BeanDefinitionBuilder builder =
       BeanDefinitionBuilder.rootBeanDefinition(MarkLogicProcessAdapter.class.getName());
   builder.setScope(BeanDefinition.SCOPE_SINGLETON);
   setInitMethodIfNeeded(builder, MarkLogicProcessAdapter.class);
   setDestroyMethodIfNeeded(builder, MarkLogicProcessAdapter.class);
   parseProperty(builder, element, "server", "server");
   parseProperty(builder, element, "port", "port");
   parseProperty(builder, element, "database", "database");
   parseProperty(builder, element, "username", "username");
   parseProperty(builder, element, "password", "password");
   BeanDefinition definition = builder.getBeanDefinition();
   setNoRecurseOnDefinition(definition);
   return definition;
 }
 public BeanDefinition parse(Element element, ParserContext parserContext) {
   BeanDefinitionBuilder builder = getBeanDefinitionBuilder(parserContext);
   builder.addConstructorArgValue("getRequestedBy");
   builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
   if (!hasAttribute(element, "config-ref")) {
     throw new BeanDefinitionParsingException(
         new Problem(
             "It seems that the config-ref for @Processor [get-requested-by] within the connector [instagram] is null or missing. Please, fill the value with the correct global element.",
             new Location(parserContext.getReaderContext().getResource()),
             null));
   }
   parseConfigRef(element, builder);
   parseProperty(builder, element, "accessTokenId");
   BeanDefinition definition = builder.getBeanDefinition();
   setNoRecurseOnDefinition(definition);
   attachProcessorDefinition(parserContext, definition);
   return definition;
 }
Esempio n. 7
0
  @Override
  protected BeanDefinition buildBeanDefinition(
      AnnotationMetadata importingClassMetadata, Class<? extends Annotation> namedAnnotation)
      throws Exception {

    String enableStateMachineEnclosingClassName = importingClassMetadata.getClassName();
    // for below classloader, see gh122
    Class<?> enableStateMachineEnclosingClass =
        ClassUtils.forName(
            enableStateMachineEnclosingClassName, ClassUtils.getDefaultClassLoader());
    // return null if it looks like @EnableStateMachine was annotated with class
    // not extending StateMachineConfigurer.
    if (!ClassUtils.isAssignable(StateMachineConfigurer.class, enableStateMachineEnclosingClass)) {
      return null;
    }

    BeanDefinitionBuilder beanDefinitionBuilder =
        BeanDefinitionBuilder.rootBeanDefinition(StateMachineDelegatingFactoryBean.class);
    AnnotationAttributes esmAttributes =
        AnnotationAttributes.fromMap(
            importingClassMetadata.getAnnotationAttributes(
                EnableStateMachine.class.getName(), false));
    Boolean contextEvents = esmAttributes.getBoolean("contextEvents");

    // check if Scope annotation is defined and set scope from it
    AnnotationAttributes scopeAttributes =
        AnnotationAttributes.fromMap(
            importingClassMetadata.getAnnotationAttributes(Scope.class.getName(), false));
    if (scopeAttributes != null) {
      String scope =
          scopeAttributes.getAliasedString("value", Scope.class, enableStateMachineEnclosingClass);
      if (StringUtils.hasText(scope)) {
        beanDefinitionBuilder.setScope(scope);
      }
    }

    beanDefinitionBuilder.addConstructorArgValue(builder);
    beanDefinitionBuilder.addConstructorArgValue(StateMachine.class);
    beanDefinitionBuilder.addConstructorArgValue(importingClassMetadata.getClassName());
    beanDefinitionBuilder.addConstructorArgValue(contextEvents);
    return beanDefinitionBuilder.getBeanDefinition();
  }
 private List<BeanDefinition> createJobListeners(final Element element) {
   List<Element> listenerElements = DomUtils.getChildElementsByTagName(element, LISTENER_TAG);
   List<BeanDefinition> result = new ManagedList<>(listenerElements.size());
   for (Element each : listenerElements) {
     String className = each.getAttribute(CLASS_ATTRIBUTE);
     BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(className);
     factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
     try {
       Class listenerClass = Class.forName(className);
       if (AbstractDistributeOnceElasticJobListener.class.isAssignableFrom(listenerClass)) {
         factory.addConstructorArgValue(each.getAttribute(STARTED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
         factory.addConstructorArgValue(
             each.getAttribute(COMPLETED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
       }
     } catch (final ClassNotFoundException ex) {
       throw new RuntimeException(ex);
     }
     result.add(factory.getBeanDefinition());
   }
   return result;
 }
  public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = getBeanDefinitionBuilder(parserContext);
    builder.addConstructorArgValue("getEstimatedPrice");
    builder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    parseConfigRef(element, builder);
    parseMapWithDefaultAndSetProperty(
        element,
        builder,
        "coordinates",
        "coordinates",
        "coordinate",
        "#[payload]",
        new ParseDelegate<String>() {

          public String parse(Element element) {
            return element.getTextContent();
          }
        });
    BeanDefinition definition = builder.getBeanDefinition();
    setNoRecurseOnDefinition(definition);
    attachProcessorDefinition(parserContext, definition);
    return definition;
  }