Announcement Announcement Module
Collapse
No announcement yet.
How to get Handle to Current Applln Context from Business Layer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      As David pointer out, the BeanFactoryLocator implementations might help - beside the Singleton implementation one can use the JNDI which works well in application servers.

      Comment

      Working...
      X