Search in sources :

Example 1 with AbstractCloudServiceConnectorFactory

use of org.springframework.cloud.service.AbstractCloudServiceConnectorFactory in project spring-cloud-connectors by spring-cloud.

the class CloudServiceIntroducer method postProcessBeanFactory.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    try {
        Constructor<?> ctor = serviceConnectorFactoryType.getConstructor(String.class, ServiceConnectorConfig.class);
        AbstractCloudServiceConnectorFactory<?> serviceFactory = (AbstractCloudServiceConnectorFactory<?>) ctor.newInstance(serviceId, serviceConnectorConfig);
        serviceFactory.setServiceConnectorType((Class) serviceConnectorType);
        serviceFactory.setBeanFactory(beanFactory);
        serviceFactory.afterPropertiesSet();
        // id is the beanId if specified, otherwise the serviceId
        if (StringUtils.hasText(beanId)) {
            beanFactory.registerSingleton(beanId, serviceFactory);
        } else {
            beanFactory.registerSingleton(serviceFactory.getServiceId(), serviceFactory);
        }
    } catch (Exception ex) {
        throw new BeanCreationException("Error registering service factory", ex);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) AbstractCloudServiceConnectorFactory(org.springframework.cloud.service.AbstractCloudServiceConnectorFactory) BeansException(org.springframework.beans.BeansException) BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Aggregations

BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 AbstractCloudServiceConnectorFactory (org.springframework.cloud.service.AbstractCloudServiceConnectorFactory)1