Search in sources :

Example 26 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project tutorials by eugenp.

the class ActivitiSpringSecurityApplication method processEngineInitializer.

@Bean
InitializingBean processEngineInitializer() {
    return new InitializingBean() {

        public void afterPropertiesSet() throws Exception {
            processEngineConfiguration.setUserEntityManager(new SpringSecurityUserManager(processEngineConfiguration, new MybatisUserDataManager(processEngineConfiguration), userManager));
            processEngineConfiguration.setGroupEntityManager(new SpringSecurityGroupManager(processEngineConfiguration, new MybatisGroupDataManager(processEngineConfiguration)));
        }
    };
}
Also used : MybatisUserDataManager(org.activiti.engine.impl.persistence.entity.data.impl.MybatisUserDataManager) MybatisGroupDataManager(org.activiti.engine.impl.persistence.entity.data.impl.MybatisGroupDataManager) SpringSecurityUserManager(com.baeldung.activiti.security.config.SpringSecurityUserManager) SpringSecurityGroupManager(com.baeldung.activiti.security.config.SpringSecurityGroupManager) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean) InitializingBean(org.springframework.beans.factory.InitializingBean)

Example 27 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinder method doBindConsumer.

/**
 * Binds an inbound channel to a given destination. The implementation delegates to
 * {@link ProvisioningProvider#provisionConsumerDestination(String, String, ConsumerProperties)}
 * and
 * {@link #createConsumerEndpoint(ConsumerDestination, String, ConsumerProperties)}
 * for handling middleware-specific logic. If the returned consumer endpoint is an
 * {@link InitializingBean} then {@link InitializingBean#afterPropertiesSet()} will be
 * called on it. Similarly, if the returned consumer endpoint is a {@link Lifecycle},
 * then {@link Lifecycle#start()} will be called on it.
 * @param name the name of the destination
 * @param group the consumer group
 * @param inputChannel the channel to be bound
 * @param properties the {@link ConsumerProperties} of the binding
 * @return the Binding for the channel
 * @throws BinderException on internal errors during binding
 */
@Override
public final Binding<MessageChannel> doBindConsumer(String name, String group, MessageChannel inputChannel, final C properties) throws BinderException {
    MessageProducer consumerEndpoint = null;
    try {
        ConsumerDestination destination = this.provisioningProvider.provisionConsumerDestination(name, group, properties);
        if (HeaderMode.embeddedHeaders.equals(properties.getHeaderMode())) {
            enhanceMessageChannel(inputChannel);
        }
        consumerEndpoint = createConsumerEndpoint(destination, group, properties);
        consumerEndpoint.setOutputChannel(inputChannel);
        this.consumerCustomizer.configure(consumerEndpoint, name, group);
        if (consumerEndpoint instanceof InitializingBean) {
            ((InitializingBean) consumerEndpoint).afterPropertiesSet();
        }
        if (properties.isAutoStartup() && consumerEndpoint instanceof Lifecycle) {
            ((Lifecycle) consumerEndpoint).start();
        }
        Binding<MessageChannel> binding = new DefaultBinding<MessageChannel>(name, group, inputChannel, consumerEndpoint instanceof Lifecycle ? (Lifecycle) consumerEndpoint : null) {

            @Override
            public Map<String, Object> getExtendedInfo() {
                return doGetExtendedInfo(destination, properties);
            }

            @Override
            public boolean isInput() {
                return true;
            }

            @Override
            protected void afterUnbind() {
                try {
                    if (getEndpoint() instanceof DisposableBean) {
                        ((DisposableBean) getEndpoint()).destroy();
                    }
                } catch (Exception e) {
                    AbstractMessageChannelBinder.this.logger.error("Exception thrown while unbinding " + toString(), e);
                }
                afterUnbindConsumer(destination, this.group, properties);
                destroyErrorInfrastructure(destination, this.group, properties);
            }
        };
        doPublishEvent(new BindingCreatedEvent(binding));
        return binding;
    } catch (Exception e) {
        if (consumerEndpoint instanceof Lifecycle) {
            ((Lifecycle) consumerEndpoint).stop();
        }
        if (e instanceof BinderException) {
            throw (BinderException) e;
        } else if (e instanceof ProvisioningException) {
            throw (ProvisioningException) e;
        } else {
            throw new BinderException("Exception thrown while starting consumer: ", e);
        }
    }
}
Also used : Lifecycle(org.springframework.context.Lifecycle) ConsumerDestination(org.springframework.cloud.stream.provisioning.ConsumerDestination) ProvisioningException(org.springframework.cloud.stream.provisioning.ProvisioningException) IOException(java.io.IOException) FluxMessageChannel(org.springframework.integration.channel.FluxMessageChannel) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) DisposableBean(org.springframework.beans.factory.DisposableBean) ProvisioningException(org.springframework.cloud.stream.provisioning.ProvisioningException) MessageProducer(org.springframework.integration.core.MessageProducer) InitializingBean(org.springframework.beans.factory.InitializingBean)

Aggregations

InitializingBean (org.springframework.beans.factory.InitializingBean)27 ApplicationContextAware (org.springframework.context.ApplicationContextAware)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)6 Bean (org.springframework.context.annotation.Bean)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MessageChannel (org.springframework.messaging.MessageChannel)4 Function (java.util.function.Function)3 DisposableBean (org.springframework.beans.factory.DisposableBean)3 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)3 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)3 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Supplier (java.util.function.Supplier)2 BeansException (org.springframework.beans.BeansException)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2