Search in sources :

Example 21 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project ignite by apache.

the class GridFactorySelfTest method getTestApplicationContext.

/**
 * Gets test Spring application context with single {@link StringBuilder} bean
 * with name "myBean" and value "Test string".
 *
 * @return Spring application context.
 */
private ApplicationContext getTestApplicationContext() {
    AbstractBeanDefinition def = new GenericBeanDefinition();
    def.setBeanClass(StringBuilder.class);
    ConstructorArgumentValues args = new ConstructorArgumentValues();
    args.addGenericArgumentValue("Test string");
    def.setConstructorArgumentValues(args);
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.registerBeanDefinition("myBean", def);
    return ctx;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 22 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project engine by craftercms.

the class BeanDefinitionUtils method createBeanDefinitionFromOriginal.

/**
 * Creates a bean definition for the specified bean name. If the parent context of the current context contains a
 * bean definition with the same name, the definition is created as a bean copy of the parent definition. This
 * method is useful for config parsers that want to create a bean definition from configuration but also want to
 * retain the default properties of the original bean.
 *
 * @param applicationContext    the current application context
 * @param beanName
 * @return the bean definition
 */
public static BeanDefinition createBeanDefinitionFromOriginal(ApplicationContext applicationContext, String beanName) {
    ApplicationContext parentContext = applicationContext.getParent();
    BeanDefinition parentDefinition = null;
    if (parentContext != null && parentContext.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
        ConfigurableListableBeanFactory parentBeanFactory = (ConfigurableListableBeanFactory) parentContext.getAutowireCapableBeanFactory();
        try {
            parentDefinition = parentBeanFactory.getBeanDefinition(beanName);
        } catch (NoSuchBeanDefinitionException e) {
        }
    }
    if (parentDefinition != null) {
        return new GenericBeanDefinition(parentDefinition);
    } else {
        return new GenericBeanDefinition();
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ApplicationContext(org.springframework.context.ApplicationContext) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 23 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.

the class LazyTagLibraryLookup method lookupTagLibrary.

@Override
public GroovyObject lookupTagLibrary(String namespace, String tagName) {
    GroovyObject tagLibrary = super.lookupTagLibrary(namespace, tagName);
    if (tagLibrary == null) {
        String tagKey = tagNameKey(namespace, tagName);
        GrailsTagLibClass taglibClass = lazyLoadableTagLibs.get(tagKey);
        if (taglibClass != null) {
            if (!applicationContext.containsBean(taglibClass.getFullName())) {
                GenericBeanDefinition bd = new GenericBeanDefinition();
                bd.setBeanClass(taglibClass.getClazz());
                bd.setAutowireCandidate(true);
                bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
                ((GenericApplicationContext) applicationContext).getDefaultListableBeanFactory().registerBeanDefinition(taglibClass.getFullName(), bd);
            }
            registerTagLib(taglibClass);
            tagLibrary = super.lookupTagLibrary(namespace, tagName);
        }
    }
    return tagLibrary;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GroovyObject(groovy.lang.GroovyObject) GrailsTagLibClass(grails.core.GrailsTagLibClass) DefaultGrailsTagLibClass(org.grails.core.DefaultGrailsTagLibClass)

Example 24 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.

the class DefaultBeanConfiguration method createBeanDefinition.

protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd = new GenericBeanDefinition();
    if (!constructorArgs.isEmpty()) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        bd.setConstructorArgumentValues(cav);
    }
    if (clazz != null) {
        bd.setLazyInit(clazz.getAnnotation(Lazy.class) != null);
        bd.setBeanClass(clazz);
    }
    bd.setScope(singleton ? AbstractBeanDefinition.SCOPE_SINGLETON : AbstractBeanDefinition.SCOPE_PROTOTYPE);
    if (parentName != null) {
        bd.setParentName(parentName);
    }
    wrapper = new BeanWrapperImpl(bd);
    return bd;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 25 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project grails-core by grails.

the class GrailsApplicationContext method registerSingleton.

/**
     * Register a singleton bean with the underlying bean factory.
     * <p>For more advanced needs, register with the underlying BeanFactory directly.
     * @see #getDefaultListableBeanFactory
     */
public void registerSingleton(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(clazz);
    bd.setPropertyValues(pvs);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Aggregations

GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)39 Test (org.junit.Test)10 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)7 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)7 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)2 AutowireCandidateQualifier (org.springframework.beans.factory.support.AutowireCandidateQualifier)2 ManagedList (org.springframework.beans.factory.support.ManagedList)2 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)2 Element (org.w3c.dom.Element)2 CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1 GrailsTagLibClass (grails.core.GrailsTagLibClass)1