Results 1 to 3 of 3

Thread: Preserving context information outside the container

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Posts
    4

    Default Preserving context information outside the container

    Hi everyone,

    I am currently using Spring and Struts together. As you know the ApplicationContextAware interface has the method setApplicationContext() which the app context calls, allows the use of app contexts (resources, events etc) - but it ties you to spring. I have read numerous articles, mission statements, and books that clearly state that you shouldn't tightly couple yourself to spring (for obvious reasons). Namely, having your objects implement ApplicationContextAware would do just that. However, these articles don't go on to demonstrate how to prevent tight coupling to the framework AND still preserve context information across various tiers (outside the container). I am utilizing Spring's IOC services by using a ContextLoaderListener and making calls in my struts action code within the container. All of this works fine. However, when I have to leave the container and make a call to my business tier, I need to preserve the context. The problem that I am finding, is that there is little documentation demonstrating how to ensure contextual information is preserved from the webtier (within the container) to the app tier (outside of the container) with out having to either:

    1.)decorate the interfaces with a helper object that would otherwise wrap information normally kept in the context
    2.)have every object implement applicationContextAware interface - which would tightly couple me to Spring.
    3.)have a common service object (that all spring-i-fied objects would extend) - another form of tight coupling.
    4.)code directly against the XMLBeanFactory (programatic approach to integrating with spring)

    Your help is appreciated.

    -Justin

  2. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    Regarding the issue of 'being tied to Spring'.

    Well your tied to Struts? So, if your going to use something make the most of it.

    To some extent there are good reasons not to make some dependencies but where does it stop?

    Here is an example I just wrote.

    My main Server shuts down its embedded servers by directly invoking shutdown on them. I thought this was not good, the embedded servers are configured in the app context, so why not just use the shutdown lifecycle stuff managed by the context. So, I just added an attribute to the servers, "destroy-method", and now the main server does a single ctx.close().

    Is this incorrectly being tied down to Spring? I'm using a Spring context and it does a bunch of stuff, why not just use it.

  3. #3
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default Re: Preserving context information outside the container

    Quote Originally Posted by jmoore
    Hi everyone,

    I am currently using Spring and Struts together. As you know the ApplicationContextAware interface has the method setApplicationContext() which the app context calls, allows the use of app contexts (resources, events etc) - but it ties you to spring. I have read numerous articles, mission statements, and books that clearly state that you shouldn't tightly couple yourself to spring (for obvious reasons). Namely, having your objects implement ApplicationContextAware would do just that. However, these articles don't go on to demonstrate how to prevent tight coupling to the framework AND still preserve context information across various tiers (outside the container). I am utilizing Spring's IOC services by using a ContextLoaderListener and making calls in my struts action code within the container. All of this works fine. However, when I have to leave the container and make a call to my business tier, I need to preserve the context. The problem that I am finding, is that there is little documentation demonstrating how to ensure contextual information is preserved from the webtier (within the container) to the app tier (outside of the container) with out having to either:

    1.)decorate the interfaces with a helper object that would otherwise wrap information normally kept in the context
    2.)have every object implement applicationContextAware interface - which would tightly couple me to Spring.
    3.)have a common service object (that all spring-i-fied objects would extend) - another form of tight coupling.
    4.)code directly against the XMLBeanFactory (programatic approach to integrating with spring)
    I'm missing out on what you think the problem is. Ideally with Struts you use the ContextLoaderPlugin, so that the Struts actions themselves are managed beans in the context, and all their dependencies, which will mostly be services they talk to, are injected into them. The actions don't know about Spring, and just talk to the services, and the services themselves have their dependencies injected, and so on.

    The main disadvantage of the ContextLoderPlugin approach is that the action paths are defined in both the struts-config file and the context. If this is bothersome, then you would use ActionSupport instead, where your Action hierarchy extends ActionSupport, and some level in the hierarchy does directly get service object from the context, but ideally you localize this to just a few base classes in the init method, so that all the main Actions are again dealing with services which they don't care how they were initialized (they're just fields set by the base class). Again, the services themselves have all their dependencies injected into them, since they are managed beans.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Passing context information between different layer
    By new springuser in forum Architecture
    Replies: 2
    Last Post: May 25th, 2005, 09:35 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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