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:co.paralleluniverse.common.spring.SpringContainerHelper.java

private static BeanDefinition getMBeanExporterBeanDefinition(String defaultDomain) {
    final AnnotationJmxAttributeSource annotationSource = new AnnotationJmxAttributeSource();

    final GenericBeanDefinition bean = new GenericBeanDefinition();
    bean.setBeanClass(MBeanExporter.class);
    MutablePropertyValues properties = new MutablePropertyValues();
    properties.add("server", ManagementFactory.getPlatformMBeanServer());
    properties.add("autodetectMode", MBeanExporter.AUTODETECT_ASSEMBLER);
    properties.add("assembler", new MetadataMBeanInfoAssembler(annotationSource));
    properties.add("namingStrategy", new MBeanNamingStrategy(annotationSource).setDefaultDomain(defaultDomain));
    bean.setPropertyValues(properties);/*  w w w .  ja v a2 s  .co  m*/
    return bean;
}

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

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

    properties.put(TEST_KEY, "");

    configurer.processProperties(beanFactory, properties);

    assertNotNull(//w w w .java  2 s .com
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals("", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}

From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java

/**
 * Register {@link CacheService} definition.
 * DefaultCacheServiceProxy delegates the DefaultCacheService on behalf of the cache hit-rate statistics.
 *///from ww w. j  ava2 s. c o  m
protected GenericBeanDefinition initCacheServiceDefinition(Element element,
        BeanDefinitionRegistry beanDefinitionRegistry) {
    GenericBeanDefinition cacheDefinition = new GenericBeanDefinition();
    cacheDefinition.setBeanClass(DefaultCacheService.class);
    cacheDefinition.setAutowireCandidate(false);
    //JDK proxy not available, as the objects are managed by the Spring IOC
    /*        DefaultCacheService cacheServiceProxy = (DefaultCacheService)Proxy.newProxyInstance(DefaultCacheService.class.getClassLoader(),new Class<?>[]{DefaultCacheService.class}, new CacheServiceInvokerHandler());
            definition.setBeanClass(cacheServiceProxy.getClass());*/

    cacheServiceId = element.getAttribute(CACHE_SERVICE_ID_ATTR);

    if (!StringUtils.hasText(cacheServiceId)) {
        cacheServiceId = DEFAULT_CACHE_SERVICE_ID;
    }

    // Add reference to CacheFactory
    ConstructorArgumentValues constructorArgumentValues = cacheDefinition.getConstructorArgumentValues();

    String cacheClientFactoryId = element.getAttribute(CACHE_CLIENT_FACTORY_ID_ATTR);
    cacheItemConfigManager = element.getAttribute(CACHE_ITEM_MANAGER_ID_ATTR);
    if (!StringUtils.hasText(cacheClientFactoryId) || !StringUtils.hasText(cacheItemConfigManager)) {
        registerCacheRelatedWebService(beanDefinitionRegistry);
    }

    if (!StringUtils.hasText(cacheClientFactoryId)) {
        cacheClientFactoryId = DEFAULT_CACHE_CLIENT_FACTORY_ID;
        // Register default cache client factory
        registerDefaultCacheClientFactory(beanDefinitionRegistry);
    }
    constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(cacheClientFactoryId));
    constructorArgumentValues
            .addGenericArgumentValue(new RuntimeBeanReference(ONEWAY_CACHE_MANAGE_WEB_SERVICE_ID));

    if (!StringUtils.hasText(cacheItemConfigManager)) {
        cacheItemConfigManager = DEFAULT_ITEM_CONFIG_MANAGER_ID;
        // Register default cache item config manager
        registerDefaultCacheItemConfigManager(beanDefinitionRegistry);
    }
    constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference(cacheItemConfigManager));

    return cacheDefinition;

    /*        BeanDefinitionHolder holder = new BeanDefinitionHolder(cacheDefinition, this.cacheServiceId);
            
            BeanDefinitionReaderUtils.registerBeanDefinition(holder, beanDefinitionRegistry);*/
}

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

@Test
public void testProcessPropertiesWithEmptyStringValue() throws Exception {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(EmptyStringValueTestBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);

    configurer.processProperties(beanFactory, properties);

    assertNotNull(/*from  www.  j a  v a 2 s.  com*/
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals("", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}

From source file:com.fitbur.testify.di.spring.SpringServiceLocator.java

@Override
public void addModule(Class<?> type) {
    GenericBeanDefinition bean = new GenericBeanDefinition();
    bean.setBeanClass(type);/*from w w w.  j  av a  2  s. c  om*/
    bean.setRole(ROLE_APPLICATION);

    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();
    beanFactory.registerBeanDefinition(type.getSimpleName(), bean);
}

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

@Test
public void testPropertyAnnotationWithNoKeyOrValue() throws Exception {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(PropertyWithNoKeyOrValueAnnotationBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);

    configurer.processProperties(beanFactory, properties);

    assertNotNull(/*from  w  ww .  jav a 2s .co  m*/
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals("", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}

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

/**
 * Verify that PropertyAnnotationAndPlaceholderConfigurer is setting annotated properties for Spring factory beans.
 * @see http://code.google.com/p/spring-property-annotations/issues/detail?id=6
 * @throws Exception/*w  w  w  . j a  v  a  2 s. c  o m*/
 */
@Test
public void testPropertyAnnotationWithFactoryBean() throws Exception {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(PropertyAnnotatedFactoryBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);
    properties.put(TEST_KEY, TEST_VALUE);

    configurer.processProperties(beanFactory, properties);

    assertNotNull(
            beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property"));
    assertEquals(TEST_VALUE, beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues()
            .getPropertyValue("property").getValue());
}

From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java

protected void registerStatisticsCacheInterceptor(Element element,
        BeanDefinitionRegistry beanDefinitionRegistry) {
    GenericBeanDefinition definition = new GenericBeanDefinition();
    definition.setBeanClass(getStatisticsCacheInterceptor());
    String cacheInterceptorId = "monitorInterceptor";
    //register the cache item config manager
    cacheItemConfigManager = element.getAttribute(CACHE_ITEM_MANAGER_ID_ATTR);
    if (!StringUtils.hasText(cacheItemConfigManager)) {
        cacheItemConfigManager = DEFAULT_ITEM_CONFIG_MANAGER_ID;
    }//from   ww w .jav a 2s .c  om
    MutablePropertyValues propertyValues = definition.getPropertyValues();
    propertyValues.addPropertyValue(cacheItemConfigManager, new RuntimeBeanReference(cacheItemConfigManager));
    BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, cacheInterceptorId);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, beanDefinitionRegistry);
}

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

/**
 * Verify that PropertyAnnotationAndPlaceholderConfigurer is setting annotated properties for objects created by Spring factory beans.
 * @see http://code.google.com/p/spring-property-annotations/issues/detail?id=6
 * @throws Exception//from   w w w. jav a 2s.  co m
 */
@Test
public void testPropertyAnnotationWithObjectsCreatedByFactoryBean() throws Exception {
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(PropertyAnnotatedFactoryBean.class);
    beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition);
    properties.put(TEST_KEY, TEST_VALUE);

    configurer.processProperties(beanFactory, properties);

    String beanName = beanFactory.getBeanNamesForType(SimplePropetyAnnotatedBean.class)[0];
    assertNotNull(beanName);
    assertEquals(TEST_VALUE, beanFactory.getBeanDefinition(beanName).getPropertyValues()
            .getPropertyValue("property").getValue());
}

From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java

protected void registerCacheProxyBean(Element element, BeanDefinitionRegistry beanDefinitionRegistry,
        GenericBeanDefinition cacheDefinition) {
    GenericBeanDefinition definition = new GenericBeanDefinition();
    definition.setBeanClass(org.springframework.aop.framework.ProxyFactoryBean.class);
    String cacheProxyId = cacheServiceProxyId;
    definition.getPropertyValues().addPropertyValue("interceptorNames", new String[] { "monitorInterceptor" });
    definition.getPropertyValues().addPropertyValue("target", cacheDefinition);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, cacheProxyId);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, beanDefinitionRegistry);
}