Example usage for org.springframework.beans.factory.support GenericBeanDefinition GenericBeanDefinition

List of usage examples for org.springframework.beans.factory.support GenericBeanDefinition GenericBeanDefinition

Introduction

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

Prototype

public GenericBeanDefinition() 

Source Link

Document

Create a new GenericBeanDefinition, to be configured through its bean properties and configuration methods.

Usage

From source file:com.khs.sherpa.spring.SpringManagedBeanFactory.java

public void loadManagedBean(String name, Class<?> type) {
    BeanDefinitionRegistry registry = ((BeanDefinitionRegistry) springApplicationContext
            .getAutowireCapableBeanFactory());
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(type);// w  w w  . j av  a  2s.  c om
    registry.registerBeanDefinition(name, beanDefinition);
}

From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java

@Test
public void testProcessPropertiesWithDefaultValueWithFieldAnnotation() {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(AnnotatedFieldTestBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);

    configurer.processProperties(beanFactory, properties);

    assertNotNull(/*from  w w w.j  av a 2 s.c om*/
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals(TEST_DEFAULT_VALUE, beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}

From source file:org.codehaus.griffon.runtime.spring.GriffonApplicationContext.java

/**
 * Register a singleton bean with the underlying bean factory.
 * <p>For more advanced needs, register with the underlying BeanFactory directly.
 * @see #getDefaultListableBeanFactory//from w ww.j  a va  2  s . c  om
 */
public void registerSingleton(String name, Class clazz) throws BeansException {
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(clazz);
    getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
}

From source file:com.laxser.blitz.web.impl.module.ModuleAppContext.java

/** ?messageSourceRose? */
public static void registerMessageSourceIfNecessary(BeanDefinitionRegistry registry,
        String[] messageBaseNames) {
    if (!ArrayUtils.contains(registry.getBeanDefinitionNames(), MESSAGE_SOURCE_BEAN_NAME)) {
        logger.debug("registerMessageSource  " + ArrayUtils.toString(messageBaseNames));
        GenericBeanDefinition messageSource = new GenericBeanDefinition();
        messageSource.setBeanClass(ReloadableResourceBundleMessageSource.class);
        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues.addPropertyValue("useCodeAsDefaultMessage", true);
        propertyValues.addPropertyValue("defaultEncoding", "UTF-8"); // propertiesUTF-8?ISO-9959-1
        propertyValues.addPropertyValue("cacheSeconds", 60); // hardcode! 60
        propertyValues.addPropertyValue("basenames", messageBaseNames);

        messageSource.setPropertyValues(propertyValues);
        registry.registerBeanDefinition(MESSAGE_SOURCE_BEAN_NAME, messageSource);
    }/*from w  w  w  . j a  v  a 2s. com*/
}

From source file:org.mybatis.spring.annotation.EnableMapperScanningTest.java

@Test
public void testScanWithNameConflict() {
    GenericBeanDefinition definition = new GenericBeanDefinition();
    definition.setBeanClass(Object.class);
    applicationContext.registerBeanDefinition("mapperInterface", definition);

    applicationContext.register(AppConfigWithPackageScan.class);

    startContext();/*from  w  ww  .j a v a2 s . c om*/

    assertSame("scanner should not overwite existing bean definition",
            applicationContext.getBean("mapperInterface").getClass(), Object.class);
}

From source file:org.codehaus.griffon.runtime.spring.GriffonApplicationContext.java

/**
 * Register a singleton bean with the underlying bean factory.
 * <p>For more advanced needs, register with the underlying BeanFactory directly.
 * @see #getDefaultListableBeanFactory//from   w w  w.  java  2  s .  c  o  m
 */
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);
}

From source file:com.longio.spring.LongioBeanFactoryPostProcessor.java

private Object getConnector(DefaultListableBeanFactory bf) {
    if (!bf.containsBeanDefinition("longio.connector")) {
        GenericBeanDefinition bdd = new GenericBeanDefinition();
        bdd.setBeanClass(NettyConnector.class);
        bf.registerBeanDefinition("longio.connector", bdd);
    }//from www  . j a v  a 2 s.c  om

    if (bf.containsBeanDefinition("longio.connector")) {

        Connector connector = (Connector) bf.getBean("longio.connector", Connector.class);

        return connector;
    }
    return null;
}

From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java

@Test
public void testProcessPropertiesWithinBasePackage() {
    configurer.setBasePackage("com.urbanmania");
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(SimplePropetyAnnotatedBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);

    properties.put(TEST_KEY, TEST_VALUE);

    configurer.processProperties(beanFactory, properties);

    assertNotNull(//from w ww . j a  v  a2  s.c  om
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals(TEST_VALUE, beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}