Blogs

SpringSource Blog

Spring Integration in 10 minutes

Mark Fisher

The Spring Integration 1.0 GA release was announced 2 months ago at SpringOne Americas, and ever since I've been meaning to write a new, up-to-date "getting started" blog post. Well, the beginning of the year is always a busy time, so my goal is to provide a hands-on example with 10 steps. Each step should take roughly one minute… unless you stop to think ;) . So, without further ado, here we go!

Step 1: Download the Spring Integration distribution

You can grab the latest version (1.0.1 at the time I'm writing this) here:
http://www.springsource.com/download/community?project=Spring%20Integration

Once the download completes, unzip the file. You will see a 'dist' directory containing the JARs that comprise the Spring Integration project. You will also see a 'lib' directory that contains dependencies.

Step 2: Create a project

I'll be using Eclipse for the example, but of course you could do this in another IDE. You can also use Maven or Ivy, but the example here is so simple, it's sufficient to just create a directory and add the JARs.

Create a new 'Java Project' (In the 'Package Explorer' view, right-click, then 'New -> Java Project'), and create a 'lib' directory within that. Then, copy the following JARs from the Spring Integration 'dist' and 'lib' directory into the project's 'lib'.
from dist:

  • org.springframework.integration-1.0.1.RELEASE.jar
  • org.springframework.integration-file-1.0.1.RELEASE.jar

from lib:

  • com.springsource.org.aopalliance-1.0.0.jar
  • com.springsource.org.apache.commons.logging-1.1.1.jar
  • org.springframework.aop-2.5.6.A.jar
  • org.springframework.beans-2.5.6.A.jar
  • org.springframework.context-2.5.6.A.jar
  • org.springframework.core-2.5.6.A.jar
  • org.springframework.transaction-2.5.6.A.jar

Refresh the 'lib' directory in Eclipse (hit F5) and add those JARs to the build-path (select the JARs, right-click, and choose "Build Path -> Add to Build Path"). Finally, create a 'blog' package in the 'src' directory.

Step 3: Begin the Spring configuration

If you're using Spring IDE or the SpringSource Tool Suite, you can add Spring project nature and just right-click the 'blog' package to create a new bean definition file. Otherwise, just create the following and name it 'config.xml':

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:si="http://www.springframework.org/schema/integration"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/integration

http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">

</beans>

We will add a single element for now. This defines a Message Channel that is backed by a Java in-memory queue and will hold up to 10 Messages at a time:

<si:channel id="channel">
    <si:queue capacity="10"/>
</si:channel>

Step 4: Define a Bootstrap Java class

Spring Integration components are simply embedded within any Spring ApplicationContext. Therefore, all we need to do is create one based on this configuration file. If running within a web-app, you could bootstrap with Spring's ContextLoaderListener, or if you run within dm Server, it will also handle this for you. For this simple example, we'll just create a main() method in a class called Bootstrap (in the 'blog' package):

public class Bootstrap {

    public static void main(String[] args) {
        new ClassPathXmlApplicationContext("blog/config.xml");
    }

}

(At any point, to quickly resolve imports in Eclipse you can "organize imports" with Ctrl+Shift+O… or Command+Shift+O on a Mac).

Step 5: Send and receive a Spring Integration Message

Now, we can access the channel from the context and send a Message. Because we don't have any subscribers yet (coming in the next couple steps), we will also receive from the same channel. This will prove that everything is configured properly. Modify the main() method so it looks like this:

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("blog/config.xml");
    PollableChannel channel = (PollableChannel) context.getBean("channel");
    channel.send(new StringMessage("Spring Integration rocks"));
    Message<?> reply = channel.receive();
    System.out.println("received: " + reply);
}

When you run that, you should see the result of the Message's toString() method printed to the console.

Step 6: Create a Service

Spring Integration aims to be non-invasive. That means we will now gradually modify the sample so that you have no code directly tied to the framework. The first thing we'll do, however, is add a POJO Service that will become a subscriber for our messages. This example is going to simply convert the String to uppercase and add some exclamation points:

public class Shouter {

    public String shout(String s) {
        return s.toUpperCase().concat("!!!");
    }

}

Step 7: Add the Service to the Spring configuration

The Service can be added as just a regular bean:

<bean id="shouter" class="blog.Shouter"/>

Next, we'll add a "Service Activator" to connect the Service bean to input and output channels. We need to rename the existing "channel" to "output", and then add a simple non-buffering channel for input. The entire configuration should look like this:

<si:channel id="input"/>

<si:channel id="output">
    <si:queue capacity="10"/>
</si:channel>

<si:service-activator input-channel="input"
                      output-channel="output"
                      ref="shouter"
                      method="shout"/>

<bean id="shouter" class="blog.Shouter"/>

Step 8: Invoke the Service by sending a Message

Modify the main() method to send a Message to the input channel and to receive from the output channel. Notice that we're also modifying the dependency lookups and that the channels are cast to different types (the 'input' channel is non-buffering, hence it is not a PollableChannel like the output is):

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("blog/config.xml");
    MessageChannel input = (MessageChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    input.send(new StringMessage("Spring Integration rocks"));
    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

Step 9: Send the output to a File

Rather than polling for output in the main() method, we can send the result directly to a File by adding a Channel Adapter. First, you can remove the queue sub-element from the output channel, since polling will not be necessary:

<si:channel id="output"/>

Add the Channel Adapter. You can specify any existing directory, and on Windows you should include the drive letter (e.g. "C:/tmp"):

<file:outbound-channel-adapter channel="output" directory="/tmp"/>

Next, you can update the Bootstrap's main() method to only send:

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("blog/config.xml");
    MessageChannel input = (MessageChannel) context.getBean("input");
    input.send(new StringMessage("Spring Integration rocks"));
}

You also need to add the 'file' namespace to the XSD configuration. The top-level 'beans' element should look like this:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:si="http://www.springframework.org/schema/integration"
       xmlns:file="http://www.springframework.org/schema/integration/file"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/integration

http://www.springframework.org/schema/integration/spring-integration-1.0.xsd

http://www.springframework.org/schema/integration/file

http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd">

Run the example, and you should see the output in a file with a ".msg" extension (you can add a filename-generator strategy, but that is beyond the scope of this post).

Step 10: Create a Gateway interface

The final step will achieve the goal of complete non-invasiveness. Rather than sending the Message to a Message Channel, it would be much cleaner to send a String as a parameter to a simple interface. Create the following interface within the 'blog' package:

public interface Gateway {

    void send(String s);

}

Then, add the following element to your configuration:

<si:gateway id="gateway" service-interface="blog.Gateway" default-request-channel="input"/>

Finally, use the Gateway in the main method instead of the channel. Now, you can simply pass a String:

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("blog/config.xml");
    Gateway gateway = (Gateway) context.getBean("gateway");
    gateway.send("Spring Integration rocks");
}

Conclusion

Hopefully that provides a decent introduction to Spring Integration. The main point to take away is that you can easily create a dedicated integration layer that uses the non-invasive Spring programming model. The real value is apparent when you start adding multiple endpoints. Then, you may need to add filters, transformers, and routers.

Spring Integration provides much more than what this sample demonstrates. To learn more, check out the various projects within the 'org.springframework.integration.samples' module (sources are available in the 'src' directory of the distribution) and read through the Reference Documentation. Of course, you can find much more information on the Spring Integration Home Page.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • TwitThis
 

32 responses


  1. Awesome post! Great work. This isn't some fancy JS widget or a web framework he's demoing. This is an architecture-healing middleware-type solution .. in 10 minutes! I don't know any other ESB I could get going (or even downloaded and installed) in 10 minutes!

    Maybe a Maven archtetype would help things along even more? Give people a working default public static void main(String[] a) project OR a working web application with the flick of a command incantation. I'd definitely be happy to help here!


  2. I found this article very, very helpful! I will admit that it took me a little longer than 10 minutes to work through this but I got everything to run. You might consider a series of articles that build on this as a foundation. How, for example, would I start building up a work-flow system using this technology? Could I build something that used primitive constructs (polling, file-based) that eventually evolved into something more substantial? I would imagine this could be done and only the configuration would really change significantly. A real life example might be something like an basic insurance claim or something like that.
    Best, Peter


  3. Peter,

    That's exactly what we plan to do. Obviously this particular sample is aimed at merely introducing the core concepts (e.g. message and channel). In future posts, we will add much more. As an example, the next post might add a Polling Consumer as a Channel Adapter for reading Files. Then, we can add transformation, routing, and more.

    Thanks for the feedback!
    Regards,
    Mark


  4. Hi, is there any milestone or nightly build based on Spring 3.0.0.M1?


  5. Thank you for good introduction to Spring integration. how would compare it to Camel? Per comment from Mr. Josh Long you should see Camel camel.apache.org. It is easy to get started. We use Spring with Camel and have good experience right away since more than one year. We build many applications for finance and trading. Camel provide many compnonents and easy api.


  6. I second Ivan's query.

    It would be very good to have a clear article (or just a comment reply) describing how Spring Integration compares to Apache Camel (and Mule). Are they competitors? Or complementary? What are their weakness and strengths? And why Spring introduce a(nother) integration library where there are already Apache Camel and/or Mule… instead of extending the existing libraries?

    Thank you.


  7. @Ivan, @Hendy:
    A comparison blog or article is something that I am very interested in myself, and I intend to pursue that when I have time to do a thorough example-based side-by-side comparison. At the same time, I would be even more interested in feedback from less biased developers who have worked with both frameworks and can speak about pros and cons from the experience of developing real-world applications. I will be on the lookout for some candidates to do exactly that. For now, I'll just provide a quick reply on some of the topics you have raised.

    First, the question of competing vs. complementing really depends on the situation. It doesn't typically make sense to use multiple frameworks targeted at the same domain for no good reason within a single project, so you do want to consider the best fit for an application. On the other hand, there may be strengths of two or more frameworks that can be used together. In that case, at least it's a conscious choice to include more than one. In the realm of enterprise integration, there is less of a barrier for this type of thing. For example, you can always use JMS or HTTP as a common gateway, or sometimes you can even use adapters that exist for that exact purpose. As an example of the latter, Camel provides adapters for connecting to a Spring Integration MessageChannel. Both Camel and Mule provide more adapters than Spring Integration does currently. We do have the Spring Extensions project for additional adapters, but the core is going to remain focused on mainstream connectivity (JMS, HTTP, Web Services, File, Mail).

    Second, the key difference between Spring Integration and these other frameworks is the programming model itself. Hopefully, that is somewhat obvious on the surface, but a detailed comparison on that level is probably worthy of another blog or article of its own. For now, I will simply say that we chose to provide a MessageChannel interface as the primary decoupling component rather than logical channels expressed as URIs. We wanted to avoid the hard-coding of something like "jms" or "file" within code, and yet we also wanted to avoid programming in XML. Instead, with Spring Integration you use XML to *wire* channels and endpoints together. I tend to describe that as horizontal dependency injection for event-driven applications (as opposed to the vertical dependency injection across application layers).

    Finally, the motivation for Spring Integration can be summarized in the following 3 points. We did not feel that any of the other frameworks adequately accomplished all of these goals:
    #1: to provide support for enterprise integration components that are fully embedded within any Spring context (notice we don't have a bootstrap class, a subclass of the ApplicationContext, etc.) In other words, the Spring ApplicationContext *is* the Message Bus, and the integration logic can be implemented with POJOs (no direct usage of the Spring Integration API is required).
    #2: to build as much as possible upon the proven core Spring foundation (JMS, Transactions, TaskExecutor, AOP, Component-scanning, etc).
    #3: to integrate seamlessly with other Spring projects (Spring Security, Spring Web Services, Spring Batch, etc.) We have also been consciously focused on OSGi compatibility from the very beginning to facilitate deployment in dm Server (see Iwein's recent blog entry for more detail on that).

    Hopefully that provides a bit of clarification.
    Regards,
    Mark


  8. Hi Mark-
    Do you have Polling Consumer as a Channel Adapter for receving MQ message examples posted? I am researching if PollingConsumer will be a solution for our project.
    thx
    heina


  9. @heina:

    We do provide both Polling and Event-Driven Consumers for JMS. For more detail on the Polling Consumer for JMS, see the first example in the JMS chapter of the reference manual: http://static.springframework.org/spring-integration/reference/htmlsingle/spring-integration-reference.html#jms


  10. Hi mark-
    thank you for the quick response.

    I have difficulty to run those 'org.springframework.integration.samples' module. After reading this jms doc, I tried the jms adapter sample w/o changing any configuration. It gave me error pasting below. (the same for many other samples) I think it is my eclipse or project classpath setting but the error did not tell me much. There are many people having the same error when I google. But no fix posted yet. Anyway, after working with spring for 4 weeks, I found errors from spring is very clueless to me.
    sorry to post it here.
    p.s. I tried the "Fixing spring modules XSD errors in eclipse" article, still give me cvc-complex-type error.

    Regarding connectionFactory, since my message is from websphere mq, is it true that I wont be able to use springframework class(org.springframework.jms.connection.CachingConnectionFactory) and have to use(org.apache.camel.component.jms.JmsComponent)?
    ——————————–
    ARNING: Ignored XML validation warning
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [outboundChannelAdapter.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'stream:stdin-channel-adapter'.


  11. @heina: I think you just need to add the JARs to your classpath (the JARs are in the 'dist' directory).

    Also, you can definitely use Spring's CachingConnectionFactory with *any* implementation of ConnectionFactory as its target. However, if you are using WebSphere MQ, then you would most likely just use a 'jndi-lookup' element in your Spring configuration instead.

    If you are still having problems, please post to the Spring Integration forum:
    http://forum.springframework.org/forumdisplay.php?f=42

    Regards,
    Mark


  12. i have done till step 5. Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'channel' is defined


  13. @jahid

    I just noticed the code is no longer formatting correctly in the blog, so you are missing some of the configuration there (like the 'channel' element in step 3!). I will post back here as soon as this is resolved.

    Regards,
    Mark


  14. @jahid

    As you can see, the code formatting has been fixed. Sorry for the confusion, and thank you for pointing it out. Now, you should be able to pick up where you left off with Step #3 :)

    Cheers,
    Mark


  15. Hi mark !

    Thanks for ur effort.
    one more confusion. till step #8 i am able to run.
    output:
    received: [Payload=SPRING INTEGRATION ROCKS!!!][Headers={springintegration_timestamp=1242976367500, springintegration_id=977f2422-9e52-4885-b5bf-e2252324eb1b}]

    but confusion in step #9
    not writing to file.

    my config.xml file:

    Regards,
    Jahid


  16. @jahid

    Your XML was not escaped and therefore doesn't appear. Can you try reformatting (e.g. with &lt; and &gt)?


  17. Hi Mark,

    Please find the below xml

    &lt?xml version="1.0" encoding="UTF-8"?&gt
    &ltbeans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:si="http://www.springframework.org/schema/integration"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd"&gt
    &ltsi:channel id="input"/&gt
    &ltsi:channel id="output"/&gt
    &ltfile:outbound-channel-adapter channel="output" directory="C:/SPRING_INTEGRATION_TEST_LOGS"/&gt
    &ltsi:service-activator input-channel="input" output-channel="output" ref="shouter" method="shout"/&gt
    &ltbean id="shouter" class="src.blog.Shouter"/&gt
    &lt/beans&gt


  18. @jahid

    Does that directory already exist? If not, go ahead and create it, then try again.

    -Mark


  19. Hi Mark,
    directory exists.
    actually it try to load the xml and after some time get some exception as follows:
    >>start
    May 29, 2009 12:04:11 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@54172f: display name [org.springframework.context.support.ClassPathXmlApplicationContext@54172f]; startup date [Fri May 29 12:04:11 IST 2009]; root of context hierarchy
    May 29, 2009 12:04:11 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [src/blog/outputToFile/config.xml]
    May 29, 2009 12:04:54 PM org.springframework.util.xml.SimpleSaxErrorHandler warning
    WARNING: Ignored XML validation warning
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
    at src.blog.outputToFile.Bootstrap.main(Bootstrap.java:15)
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 15 in XML document from class path resource [src/blog/outputToFile/config.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'file:outbound-channel-adapter'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at

    package src.blog.outputToFile;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.integration.channel.PollableChannel;
    import org.springframework.integration.core.MessageChannel;
    import org.springframework.integration.message.StringMessage;
    import org.springframework.integration.message.GenericMessage;

    public class Bootstrap {

    public static void main(String[] args) {
    try{
    System.out.println(">>start");
    ApplicationContext context = new ClassPathXmlApplicationContext("src/blog/outputToFile/config.xml");
    System.out.println(">>start 1");
    MessageChannel input = (MessageChannel) context.getBean("input");
    boolean isSendSuccess = input.send(new StringMessage("Spring Integration Test"));
    System.out.println(">>>>>isSendSuccess=" isSendSuccess);
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    }


  20. Hi jahid,

    Error

    "cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'file:outbound-channel-adapter"

    I able to reproduce this error when I remove

    "http://www.springframework.org/schema/integration/file "

    from the beans definition. Make sure you have this line in your config xml. As per the xml I saw above you have that already.


  21. when running step 9, an exception occured:

    Caused by: java.lang.IllegalArgumentException: No poller has been defined for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0', and no default poller is available within the context.

    Fixed by adding default poller into config.xml, e.g.

    <si:poller max-messages-per-poll="1" id="defaultPoller"
    default="true">
    <si:interval-trigger interval="30000" />
    </si:poller>


  22. Simple but excellent examples!!

    Thanks…


  23. The Gateway object gateway doesn't know about a send(String) method… with version 1.0.3.RELEASE of SI.


  24. very interesting Logic on Spring. i will try it.


  25. Hi Mark,

    Thanks for this 10 minutes hands on tutorial. Using a more recent versions (I am using Spring Integration 1.0.4.RELEASE, Spring Core 3.0.2.RELEASE) I managed to run the sample application successfully until Step 5. I ran them from JUnit runner successfully.

    Then the step 6 is just a configuration. However when I encountered Step 7, I cannot find the "input-channel" property under the si:service-activator (other like "output-channel", "method" and "ref" are still there).

    Is there any changes between the version in this tutorial and 1.0.4.RELEASE for the service-activator?

    Daniel


  26. Good demo :)

    Though I had to add these libraries too:-
    org.springframework.asm
    org.springframework.expression


  27. Hi Mark,
    As per your suggestion I have created a post on the forum

    http://forum.springsource.org/showthread.php?p=317952#post317952

    Could you please look into it.

    Your help will be appreciated !!


  28. Can any one provide me sample with spring integration for act as proxy to webservice which exposed by some other system.

    typically spring integartion should expose a wsdl on receving the messages it should call the actual webservice and get the response and forward to the calling system.Is thsi possible with srping integartion,


  29. Hi Mark,

    Congratulations thats a superb post – very informative. This post should really live on the Spring Community site and be accessible somewhere there as a quick intro into the technology. I wish every technology had a 10-tutorial like this that cover so many aspects of the technology and allows someone to get right into the technology so quickly.

    I have one requests and one suggestion,
    1. Would it be possible to provide an updated example for the latest release?
    I had originally downloaded Release 2.X and I couldnt follow the tutorial because the latest release didnt have the JAR files you described above. I then downloaded the older Release to match your example and it worked fine.
    2. Would it be an idea to extend the example slightly to cover how JUnit would be incorporated into the framework ?


  30. Hi, I could not execute the example

    Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.beans.factory.support.RootBeanDefinition.(Ljava/lang/String;)V
    at org.springframework.integration.config.xml.DefaultConfiguringBeanFactoryPostProcessor.registerIdGeneratorConfigurer(DefaultConfiguringBeanFactoryPostProcessor.java:82)
    at org.springframework.integration.config.xml.DefaultConfiguringBeanFactoryPostProcessor.postProcessBeanFactory(DefaultConfiguringBeanFactoryPostProcessor.java:59)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:554)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:545)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:363)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
    at com.BootStrap.main(BootStrap.java:15)

    Geting this error.
    Can you suggest something??

    Thanks and Regards,
    Arvind Waiker


  31. Hi,
    I am getting an error in step 5 as Message is not a generic type i have included all those mentioned jar.Suggest me.


  32. Thanks really help a lot.

7 trackbacks

Leave a Reply