Results 1 to 8 of 8

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

Hybrid View

  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,840

    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,840

    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,840

    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?

Posting Permissions

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