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

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

Introduction

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

Prototype

public void setBeanClass(@Nullable Class<?> beanClass) 

Source Link

Document

Specify the class for this bean.

Usage

From source file:com.zuoxiaolong.niubi.job.spring.config.JobDrivenBeanDefinitionParser.java

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    beanDefinition.setBeanClass(SpringContextJobDriver.class);
    propertyValues.addPropertyValue("packagesToScan", element.getAttribute("packagesToScan"));
    beanDefinition.setPropertyValues(propertyValues);
    beanDefinition.setInitMethodName("init");
    BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry());
    return beanDefinition;
}

From source file:com.googlecode.ehcache.annotations.key.SpELCacheKeyGenerator.java

/**
 * Create a new key generator with the specified name.
 *//*from   w w  w.jav a2 s  . com*/
@SuppressWarnings("unchecked")
protected CacheKeyGenerator<Serializable> createKeyGenerator(String name,
        Class<CacheKeyGenerator<Serializable>> keyGeneratorClass, MutablePropertyValues properties) {

    final AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(keyGeneratorClass);

    if (this.reflectionHelper != null
            && ReflectionHelperAware.class.isAssignableFrom(beanDefinition.getBeanClass())) {
        properties.addPropertyValue("reflectionHelper", this.reflectionHelper);
    }
    beanDefinition.setPropertyValues(properties);

    this.cacheKeyBeanFactory.registerBeanDefinition(name, beanDefinition);

    return this.cacheKeyBeanFactory.getBean(name, CacheKeyGenerator.class);
}

From source file:grails.plugin.cache.CacheBeanPostProcessor.java

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
    log.info("postProcessBeanDefinitionRegistry start");

    AbstractBeanDefinition beanDef = findBeanDefinition(registry);
    if (beanDef == null) {
        log.error("Unable to find the AnnotationCacheOperationSource bean definition");
        return;//from   w w w  .  j  a  v  a2  s .co  m
    }

    // change the class to the plugin's subclass
    beanDef.setBeanClass(GrailsAnnotationCacheOperationSource.class);

    // wire in the dependency for the grailsApplication
    MutablePropertyValues props = beanDef.getPropertyValues();
    if (props == null) {
        props = new MutablePropertyValues();
        beanDef.setPropertyValues(props);
    }
    props.addPropertyValue("grailsApplication", new RuntimeBeanReference("grailsApplication", true));

    log.debug("updated {}", beanDef);
}

From source file:org.os890.ds.addon.spring.impl.CdiAwareBeanFactoryPostProcessor.java

private BeanDefinition createSpringBeanDefinition(Bean<?> cdiBean) throws Exception {
    AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
    Set<Type> beanTypes = new HashSet<Type>(cdiBean.getTypes());
    beanTypes.remove(Object.class);
    beanTypes.remove(Serializable.class);

    Type beanType = beanTypes.size() == 1 ? beanTypes.iterator().next() : null;

    if (beanType instanceof Class) { //to support producers
        beanDefinition.setBeanClass((Class) beanType);
    } else { //fallback since spring doesn't support multiple types
        beanDefinition.setBeanClass(cdiBean.getBeanClass());
    }/*from   w w  w  . j a  va 2s . c o  m*/

    beanDefinition.setScope(CdiSpringScope.class.getName());

    for (Annotation qualifier : cdiBean.getQualifiers()) {
        if (Any.class.equals(qualifier.annotationType()) || Default.class.equals(qualifier.annotationType())) {
            continue;
        }
        //currently only simple qualifiers are supported
        AutowireCandidateQualifier springQualifier = new AutowireCandidateQualifier(qualifier.annotationType());

        for (Method annotationMethod : qualifier.annotationType().getDeclaredMethods()) {
            if (!annotationMethod.isAnnotationPresent(Nonbinding.class)) {
                springQualifier.setAttribute(annotationMethod.getName(), annotationMethod.invoke(qualifier));
            }
        }
        beanDefinition.addQualifier(springQualifier);
    }
    beanDefinition.setLazyInit(true);
    return beanDefinition;
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testExplicitScopeInheritanceForChildBeanDefinitions() throws Exception {
    String theChildScope = "bonanza!";

    RootBeanDefinition parent = new RootBeanDefinition();
    parent.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);

    AbstractBeanDefinition child = BeanDefinitionBuilder.childBeanDefinition("parent").getBeanDefinition();
    child.setBeanClass(TestBean.class);
    child.setScope(theChildScope);/* w w  w.j a  v  a 2  s .co m*/

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("parent", parent);
    factory.registerBeanDefinition("child", child);

    AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child");
    assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testScopeInheritanceForChildBeanDefinitions() throws Exception {
    RootBeanDefinition parent = new RootBeanDefinition();
    parent.setScope("bonanza!");

    AbstractBeanDefinition child = new ChildBeanDefinition("parent");
    child.setBeanClass(TestBean.class);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("parent", parent);
    factory.registerBeanDefinition("child", child);

    BeanDefinition def = factory.getMergedBeanDefinition("child");
    assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope());
}