Example usage for org.springframework.beans.factory.support RootBeanDefinition setTargetType

List of usage examples for org.springframework.beans.factory.support RootBeanDefinition setTargetType

Introduction

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

Prototype

public void setTargetType(@Nullable Class<?> targetType) 

Source Link

Document

Specify the target type of this bean definition, if known in advance.

Usage

From source file:org.wso2.msf4j.spring.MSF4JBeanDefinitionRegistryPostProcessor.java

private void registerBeanDefinition(BeanDefinitionRegistry registry, String beanName, Class beanClass) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
    beanDefinition.setTargetType(beanClass);
    beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
    registry.registerBeanDefinition(beanName, beanDefinition);
}

From source file:gr.abiss.calipso.fs.FilePersistenceConfigPostProcessor.java

@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    if (this.repositoryClass == null) {

        LOGGER.debug("Adding FilePersistenceService bean using: " + this.repositoryClassName);
        if (StringUtils.isBlank(this.repositoryClassName)) {
            this.repositoryClassName = ConfigurationFactory.getConfiguration()
                    .getString(ConfigurationFactory.FS_IMPL_CLASS);
        }//  w w  w .  j a  v  a  2s  . c o m

        try {
            this.repositoryClass = FilePersistenceConfigPostProcessor.class.forName(this.repositoryClassName);
        } catch (ClassNotFoundException e) {
            LOGGER.error("Failed to obtain repository class: " + this.repositoryClassName
                    + ", will fallback to default");
        }
    }
    if (this.repositoryClass == null) {
        this.repositoryClass = DummyFilePersistenceServiceImpl.class;
    }

    RootBeanDefinition beanDefinition = new RootBeanDefinition(this.repositoryClass); //The service implementation
    beanDefinition.setTargetType(FilePersistenceService.class); //The service interface
    //beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
    registry.registerBeanDefinition(FilePersistenceService.BEAN_ID, beanDefinition);

    LOGGER.debug("Added FilePersistenceService bean using: " + this.repositoryClass.getName());
}

From source file:org.exoplatform.container.spring.SpringContainer.java

/**
 * {@inheritDoc}/*from   www .  ja  v a 2s .  c o  m*/
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void start() {
    ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false);
    // We check if the component has been defined in the configuration of the current container
    // The goal is to enable the SpringContainer only if it is needed
    Component component = cm.getComponent(ApplicationContextProvider.class);
    if (component == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                    "No ApplicationContextProvider has been defined, thus the SpringContainer will be disabled."
                            + " To enable the Spring Integration please define an ApplicationContextProvider");
        }
    } else {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
        Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters();
        for (ComponentAdapter<?> adapter : adapters) {
            Object key = adapter.getComponentKey();
            String name = keyToBeanName(key);
            String factoryName = name + "#factory";
            RootBeanDefinition def = new RootBeanDefinition(adapter.getComponentImplementation(),
                    AbstractBeanDefinition.AUTOWIRE_NO, false);
            def.setScope(BeanDefinition.SCOPE_PROTOTYPE);
            def.setFactoryBeanName(factoryName);
            def.setFactoryMethodName("getInstance");
            def.setLazyInit(true);
            def.setTargetType(adapter.getComponentImplementation());
            if (key instanceof String) {
                def.addQualifier(new AutowireCandidateQualifier(Named.class, key));
            } else if (key instanceof Class<?> && ((Class<?>) key).isAnnotation()) {
                def.addQualifier(new AutowireCandidateQualifier((Class<?>) key));
            } else {
                def.setPrimary(true);
            }
            bf.registerBeanDefinition(name, def);
            bf.registerSingleton(factoryName, new ComponentAdapterFactoryBean(adapter));
        }
        GenericApplicationContext parentContext = new GenericApplicationContext(bf);
        parentContext.refresh();
        ApplicationContextProvider provider = super.getComponentInstanceOfType(ApplicationContextProvider.class,
                false);
        ctx = provider.getApplicationContext(parentContext);
        LOG.info("A SpringContainer has been enabled using the ApplicationContextProvider "
                + provider.getClass());
    }
    super.start();
}