Java Code Examples for org.springframework.jms.config.MethodJmsListenerEndpoint#setBeanFactory()

The following examples show how to use org.springframework.jms.config.MethodJmsListenerEndpoint#setBeanFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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
 */
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);
}
 
Example 2
Source File: JmsListenerAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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
 */
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);
}
 
Example 3
Source File: JmsListenerAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
protected void processJmsListener(JmsListener jmsListener, Method mostSpecificMethod, Object bean) {
	Method invocableMethod = MethodIntrospector.selectInvocableMethod(mostSpecificMethod, bean.getClass());

	MethodJmsListenerEndpoint endpoint = createMethodJmsListenerEndpoint();
	endpoint.setBean(bean);
	endpoint.setMethod(invocableMethod);
	endpoint.setMostSpecificMethod(mostSpecificMethod);
	endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
	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);
}