Announcement Announcement Module
Collapse
No announcement yet.
Spring integration configuration: using both XML and annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring integration configuration: using both XML and annotations

    Hello,

    I'm not a fan of XML files, but I love the Spring integration graph that STS shows you. Besides, I'm used to configuring Spring applications with XML from the very first releases.

    However, I also loves the component scan and auto-wired features of Spring using annotations.

    Thus, I'm configuring a Spring integration application with XML files, BUT I'm also using Spring integration annotations. Mainly to load beans (using @Component), but also for documentation purposes (for instance, to point that a method is a @ServiceActivator or a @splitter).

    I'm configuring neither inputChannel nor outputChannel, because I'm relying in the XML file for that.

    For instance, a splitter:

    HTML Code:
    <int:splitter id="mySplitter" input-channel="inputChannel" output-channel="outputChannel" ref="requestSplitter" method="splitRequests" />
    Being:

    Code:
    @Component
    public class RequestSplitter {
    	
    	@Splitter
    	public List<Item> splitRequests(List<Request> requests) {
    		//TODO: fill the list
    		return new ArrayList<Item>();
    	}
    }
    For the time being I don't have any problems with all this stuff, but I wonder, is there any known problems with this approach?

  • #2
    Hello

    What I may to show you it just some JIRAs with annotation problems:
    https://jira.springsource.org/browse/INT-1834
    https://jira.springsource.org/browse/INT-639

    And about your config:
    1. if use both ref and method attributes on the XML component you don't need an annotation on that method. On the background will be createed some MethodHandler
    2. If you have an annotation on the method you don't need method attribute on the XML component. MethodHandler will be based on the annotation for this XML component
    3. If you have an annotated method for top-level message handling you don't need XML component at all. Just use inputChannel and outputChannel properties of that annotation.

    And from me: I don't like annotation message flow configuration. It looks like procedure programming and breaks loosely coupled principle. The XML config looks a bit clear and it's realy a config for message flow. In many cases there is no any reason to write any Java code, e.g. receiving Message from JMS and sending it into e-mail.

    Cheers,
    Artem
    2. You

    Comment


    • #3
      Thank you very much for your clear response.

      Besides, it's interesting to see current issues when managing flows with annotated methods.

      I was worried about any kind of collisions when MethodHandler is created for processing the annotations and parsing the XML configuration, in my current configuration.

      Since I agree with you, I'd rather XML configuration because it's more clear and more loosely coupled, if I had any problem, I would remove the annotations (that I'm currently using for documentation purposes, as I said)

      Thanks a lot.
      Greetings.

      Javier.

      Comment

      Working...
      X