Search in sources :

Example 16 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerMessageConverter.

private RuntimeBeanReference registerMessageConverter(Element element, ParserContext context, Object source) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> converters = new ManagedList<>();
    if (convertersElement != null) {
        converters.setSource(source);
        for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
            Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
            converters.add(object);
        }
    }
    if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
        converters.setSource(source);
        converters.add(new RootBeanDefinition(StringMessageConverter.class));
        converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
        if (jackson2Present) {
            RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
            RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
            resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
            jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
            // Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
            GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
            jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
            jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
            jacksonFactoryDef.setSource(source);
            jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
            converters.add(jacksonConverterDef);
        }
    }
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addIndexedArgumentValue(0, converters);
    RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null);
    String name = MESSAGE_CONVERTER_BEAN_NAME;
    registerBeanDefByName(name, messageConverterDef, context, source);
    return new RuntimeBeanReference(name);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ByteArrayMessageConverter(org.springframework.messaging.converter.ByteArrayMessageConverter) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 17 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project disconf by knightliao.

the class DisconfMgrBean method registerAspect.

/**
     * register aspectJ for disconf get request
     *
     * @param registry
     */
private void registerAspect(BeanDefinitionRegistry registry) {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(DisconfAspectJ.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.setAbstract(false);
    beanDefinition.setAutowireCandidate(true);
    beanDefinition.setScope("singleton");
    registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 18 with GenericBeanDefinition

use of org.springframework.beans.factory.support.GenericBeanDefinition in project spring-security by spring-projects.

the class MessageSecurityPostProcessorTest method handlesBeansWithoutClass.

@Test
public void handlesBeansWithoutClass() {
    BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    registry.registerBeanDefinition("beanWithoutClass", new GenericBeanDefinition());
    postProcessor.postProcessBeanDefinitionRegistry(registry);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) Test(org.junit.Test)

Example 19 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) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(clazz);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 20 with GenericBeanDefinition

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

the class GrailsApplicationContext method registerPrototype.

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

Aggregations

GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)37 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 TestBean (org.springframework.tests.sample.beans.TestBean)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)3 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