Example usage for org.springframework.jms.config MethodJmsListenerEndpoint setBeanFactory

List of usage examples for org.springframework.jms.config MethodJmsListenerEndpoint setBeanFactory

Introduction

In this page you can find the example usage for org.springframework.jms.config MethodJmsListenerEndpoint setBeanFactory.

Prototype

@Override
public void setBeanFactory(@Nullable BeanFactory beanFactory) 

Source Link

Document

Set the BeanFactory to use to resolve expressions (may be null ).

Usage

From source file:org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor.java

/**
 * Process the given {@link JmsListener} annotation on the given method,
 * registering a corresponding endpoint for the given bean instance.
 * @param jmsListener the annotation to process
 * @param mostSpecificMethod the annotated method
 * @param bean the instance to invoke the method on
 * @see #createMethodJmsListenerEndpoint()
 * @see JmsListenerEndpointRegistrar#registerEndpoint
 *///from  w w  w .  jav  a 2  s . com
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
    Method invocableMethod = AopUtils.selectInvocableMethod(mostSpecificMethod, bean.getClass());

    MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
    endpoint.setBean(bean);
    endpoint.setMethod(invocableMethod);
    endpoint.setMostSpecificMethod(mostSpecificMethod);
    endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
    endpoint.setEmbeddedValueResolver(this.embeddedValueResolver);
    endpoint.setBeanFactory(this.beanFactory);
    endpoint.setId(getEndpointId(jmsListener));
    endpoint.setDestination(resolve(jmsListener.destination()));
    if (StringUtils.hasText(jmsListener.selector())) {
        endpoint.setSelector(resolve(jmsListener.selector()));
    }
    if (StringUtils.hasText(jmsListener.subscription())) {
        endpoint.setSubscription(resolve(jmsListener.subscription()));
    }
    if (StringUtils.hasText(jmsListener.concurrency())) {
        endpoint.setConcurrency(resolve(jmsListener.concurrency()));
    }

    JmsListenerContainerFactory<?> factory = null;
    String containerFactoryBeanName = resolve(jmsListener.containerFactory());
    if (StringUtils.hasText(containerFactoryBeanName)) {
        Assert.state(this.beanFactory != null,
                "BeanFactory must be set to obtain container factory by bean name");
        try {
            factory = this.beanFactory.getBean(containerFactoryBeanName, JmsListenerContainerFactory.class);
        } catch (NoSuchBeanDefinitionException ex) {
            throw new BeanInitializationException("Could not register JMS listener endpoint on ["
                    + mostSpecificMethod + "], no " + JmsListenerContainerFactory.class.getSimpleName()
                    + " with id '" + containerFactoryBeanName + "' was found in the application context", ex);
        }
    }

    this.registrar.registerEndpoint(endpoint, factory);
}