PDA

View Full Version : MessageBusParser


Yasson
Mar 6th, 2008, 05:47 PM
Hi guys.
I've just tried to make my first HelloWorld spring-integration app, and got the exception: No bean named 'internal.MessageBus' is defined.

Here is my context:



<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<message-bus/>

<beans:bean id="helloService" class="com.integration.HelloService"/>

<endpoint input-channel="inputChannel"
default-output-channel="outputChannel"
handler-ref="helloService"
handler-method="sayHello" />

</beans:beans>



HelloService class:

package com.integration;

public class HelloService {

public String sayHello(String name) {

return "Hello" + name;

}

}


here is how I run the example:

ApplicationContext context = new ClassPathXmlApplicationContext("integrationContext.xml");

ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_ NAME);
MessageChannel inputChannel = channelRegistry.lookupChannel("inputChannel");
MessageChannel outputChannel = channelRegistry.lookupChannel("outputChannel");
inputChannel.send(new StringMessage(new Integer(1),"World"));
System.out.println(outputChannel.receive().getPayl oad());


Could you please point me on whats whrong here?

Thanks.

Mark Fisher
Mar 6th, 2008, 11:05 PM
That context file you've provided is named "integrationContext.xml" and is located at the root of the classpath?

Yasson
Mar 7th, 2008, 01:55 PM
Yes. The context file is visible by application.
Here is the stack trace:


org.springframework.beans.factory.UnsatisfiedDepen dencyException: Error creating bean with name 'org.springframework.integration.scheduling.Subscr iption#0': Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.integration.channel.MessageCha nnel]: Could not convert constructor argument value of type [java.lang.String] to required type [org.springframework.integration.channel.MessageCha nnel]: Failed to convert value of type [java.lang.String] to required type [org.springframework.integration.channel.MessageCha nnel]; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [org.springframework.integration.channel.MessageCha nnel]: no matching editors or conversion strategy found
at org.springframework.beans.factory.support.Construc torResolver.createArgumentArray(ConstructorResolve r.java:501)
at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:176)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:796)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:489)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 46)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:166)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:243)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:167)
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:252)
at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:102)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1193)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:961)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:507)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 46)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:166)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:243)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:167)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:268)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:257)
at org.springframework.context.support.AbstractApplic ationContext.getBeansOfType(AbstractApplicationCon text.java:887)
at org.springframework.integration.bus.MessageBus.reg isterEndpoints(MessageBus.java:155)
at org.springframework.integration.bus.MessageBus.set ApplicationContext(MessageBus.java:103)
at org.springframework.context.support.ApplicationCon textAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java:72)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInitialization(AbstractAutowireCapableBeanFa ctory.java:315)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1275)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:510)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 46)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:166)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:243)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:167)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:351)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:689)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:358)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:91)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:75)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:65)
at com.integration.TestIntegration.main(TestIntegrati on.java:14)

Mark Fisher
Mar 7th, 2008, 02:03 PM
Sorry that I didn't notice this the first time, but you haven't defined the "inputChannel" and "outputChannel" beans. There are two options:

1) define them explicitly in the xml (with the advantage of being able to configure properties such as 'capacity' and also provide interceptors if desired):

<channel id="inputChannel"/>
<channel id="outputChannel"/>


2) enable the 'auto-create-channels' option for the MessageBus:

<message-bus auto-create-channels="true"/>


-Mark

Yasson
Mar 7th, 2008, 02:08 PM
Huh. Thanks It works now.
There is nothing about that in the example I found in internet.

Thanks again.