Results 1 to 3 of 3

Thread: How to get Handle to Current Applln Context from Business Layer

  1. #1
    Join Date
    Jul 2006
    Posts
    19

    Default How to get Handle to Current Applln Context from Business Layer

    I have 3 layers -

    Web Layer - Business Layer - DAO Layer

    Currently all 3 layers share same context (which is provided by ContextLoader when the web layer boots up )

    But in my service layer (or POJO layer) I want to get access to my current application context to get access to a bean which will be created in prototype mode by the context.

    How do I get access to appln context from one of my methods in bussiness layer. (without making assumptions that my layer will always be collocated with web layer)

    Just like we have WebApplicationContextUtils, similar to that do we have any class that returns handle to current appln context which is loaded?

    Regards
    Ajay

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    You can implement ApplicationContextAware - but it comes with a health warning: using it can be a code smell, because it can subvert inversion of control. I like your idea of separate contexts for your layers. There is support for parent contexts in the ContextLoader (which is used by the ContextLoaderListener that you are already probably using). And a servlet application context is always a separate child context. For more flexible options take a look at SingletonBeanFactoryLocator.

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    As David pointer out, the BeanFactoryLocator implementations might help - beside the Singleton implementation one can use the JNDI which works well in application servers.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

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