Results 1 to 8 of 8

Thread: Spring Integration + webapps: accesing beans in the main context

  1. #1
    Join Date
    Mar 2008
    Posts
    4

    Default Spring Integration + webapps: accesing beans in the main context

    Hi all,
    I have Spring Integration working within a webapp (using Tomcat). Following another post in this forum, I got it starting a different context for the integration part, from a bean initialized in the main webapp.
    It works fine now, but... I cannot access the beans of the webapp context. I'd like to use some of the business layer services. They are using spring transactions (@Transactional on their interfaces), so instantiate them "by hand" doesn't seem to be a good option.
    Any idea?

    Thanks in advance

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,843

    Default

    Can you explain the separation of your application contexts in a bit more detail?

    The simplest solution is probably to include the Spring Integration configuration files within the "contextConfigLocation" parameter so that your ContextLoaderListener will create the integration components within the same context as your service layer.

  3. #3
    Join Date
    Mar 2008
    Posts
    4

    Default

    The thing is that I wasn't able to get spring integration working within the context of a web application. I guess it's related with some limitation of the WebApplicationContext...
    So, following the instruction of this thread, I'm initializating a new context from a bean of the web application, containing all the spring integration stuff. That's why I have two different contexts.
    After some try and fix, now I'm accesing the beans of the main context by accessing directly the web application context with
    WebApplicationContext webContext = ContextLoader.getCurrentWebApplicationContext();
    webContext.getBean("BeanName");

    It actually works fine, but I still find the solution a little bit "dirty"

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,843

    Default

    What version of Spring Integration are you using? The auto-startup for MessageBus was added in M2.

  5. #5
    Join Date
    Mar 2008
    Posts
    4

    Default

    I'm using 1.0.0.m2 (downloaded from your maven repository: http://s3.amazonaws.com/maven.spring....org/milestone)

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,843

    Default

    The M2 version of MessageBus has autoStartup="true" by default. So, it should be finding all channel and endpoint definitions within its context and then activating those endpoints. Can you provide a code excerpt of what you are having to do manually?

  7. #7
    Join Date
    Mar 2008
    Posts
    4

    Default

    Oh damn! I got in a mess with the versions because I haven't realized that "spring-integration-adapters" was a different maven artifact in milestone 2, so in some deseperation moment I went back to m1...
    Now it works fine without all that workarounds.

    Many thanks for your efforts Mark

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,843

    Default

    Glad to hear that it's working! Sorry about the confusion with the different JAR. Be sure to consult the README.TXT file within each new release (especially during the milestone phases) in case there are additional modularity changes.

    -Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •