Example usage for org.springframework.beans.factory.support AbstractBeanDefinition setAutowireCandidate

List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition setAutowireCandidate

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support AbstractBeanDefinition setAutowireCandidate.

Prototype

@Override
public void setAutowireCandidate(boolean autowireCandidate) 

Source Link

Document

Set whether this bean is a candidate for getting autowired into some other bean.

Usage

From source file:com.nominanuda.springmvc.MvcFrontControllerBeanDefinitionParser.java

protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    if (plugins == null) {
        try {/*w w w. j  a  v  a 2 s .c  om*/
            initPlugins(parserContext);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    BeanDefinitionBuilder bdBuilder = BeanDefinitionBuilder.rootBeanDefinition(HandlerMatcherMapping.class);

    String pattern = ((Element) element.getElementsByTagNameNS(ns, "pattern").item(0)).getTextContent();

    String uriSpec = getUriSpec(pattern);
    BeanDefinitionBuilder matchBuilder = BeanDefinitionBuilder.genericBeanDefinition(URISpecMatcher.class);
    matchBuilder.addPropertyValue("spec", pattern);
    String matchId = uuid();
    parserContext.getRegistry().registerBeanDefinition(matchId, matchBuilder.getBeanDefinition());
    bdBuilder.addPropertyReference("handlerMatcher", matchId);
    String handlerId = generateHandler(element, parserContext, uriSpec);
    matchBuilder.addPropertyReference("handler", handlerId);
    List<BeanMetadataElement> filters = generateFilterList(element, parserContext, uriSpec);
    if (filters != null) {
        matchBuilder.addPropertyValue("handlerFilters", filters);
    }
    AbstractBeanDefinition abd = bdBuilder.getBeanDefinition();
    abd.setAutowireCandidate(false);
    return abd;
}

From source file:atunit.spring.SpringContainer.java

protected AbstractBeanDefinition defineAutowireBean(Class<?> type) throws Exception {
    AbstractBeanDefinition beandef = BeanDefinitionReaderUtils.createBeanDefinition(null, type.getName(),
            type.getClassLoader());// w ww .  ja va  2 s  . com
    beandef.setAutowireCandidate(true);
    beandef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT);
    return beandef;
}

From source file:atunit.spring.SpringContainer.java

protected AbstractBeanDefinition defineInstanceHolderFactoryBean(Class<?> type, Object instance)
        throws Exception {
    ConstructorArgumentValues args = new ConstructorArgumentValues();
    args.addIndexedArgumentValue(0, type);
    args.addIndexedArgumentValue(1, instance);

    AbstractBeanDefinition beandef = BeanDefinitionReaderUtils.createBeanDefinition(null,
            InstanceHolderFactoryBean.class.getName(), getClass().getClassLoader());
    beandef.setConstructorArgumentValues(args);
    beandef.setAutowireCandidate(true);
    return beandef;
}

From source file:org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.java

/**
 * Apply the attributes of the given bean element to the given bean * definition.
 * @param ele bean declaration element//  www .jav a  2  s  .  c om
 * @param beanName bean name
 * @param containingBean containing bean definition
 * @return a bean definition initialized according to the bean element attributes
 */
public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName,
        @Nullable BeanDefinition containingBean, AbstractBeanDefinition bd) {

    if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
        error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele);
    } else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) {
        bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE));
    } else if (containingBean != null) {
        // Take default from containing bean in case of an inner bean definition.
        bd.setScope(containingBean.getScope());
    }

    if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) {
        bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE)));
    }

    String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE);
    if (DEFAULT_VALUE.equals(lazyInit)) {
        lazyInit = this.defaults.getLazyInit();
    }
    bd.setLazyInit(TRUE_VALUE.equals(lazyInit));

    String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE);
    bd.setAutowireMode(getAutowireMode(autowire));

    if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
        String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE);
        bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS));
    }

    String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE);
    if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) {
        String candidatePattern = this.defaults.getAutowireCandidates();
        if (candidatePattern != null) {
            String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern);
            bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName));
        }
    } else {
        bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate));
    }

    if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) {
        bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE)));
    }

    if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) {
        String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE);
        bd.setInitMethodName(initMethodName);
    } else if (this.defaults.getInitMethod() != null) {
        bd.setInitMethodName(this.defaults.getInitMethod());
        bd.setEnforceInitMethod(false);
    }

    if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) {
        String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE);
        bd.setDestroyMethodName(destroyMethodName);
    } else if (this.defaults.getDestroyMethod() != null) {
        bd.setDestroyMethodName(this.defaults.getDestroyMethod());
        bd.setEnforceDestroyMethod(false);
    }

    if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) {
        bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE));
    }
    if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) {
        bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE));
    }

    return bd;
}