Announcement Announcement Module
Collapse
No announcement yet.
Retrieve app context from POJO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieve app context from POJO

    Hi,

    I have a web application where the application context files are placed in the WEB-INF directory. I would like to retrieve these context files from a regular POJO that has no access to the servlet context or does not even know its in a web environment. I tried using ClassPathXml... to no avail. I want to avoid absolute paths or anything dependent on the OS directories. I also looked into XmlWebApplicationContext but I don't know how to use this appropriately. Any help would be appreciated. Thanks in advance.

    -los

  • #2
    Sure, just have your POJO implement the ApplicationContextAware interface. It will allow you to have a local reference to the app context files. Page 143 of Rob Harrop's Pro Spring book, or just google the interface name above for examples.

    Glen

    Comment


    • #3
      I'm having this same problem

      Originally posted by gmazza
      Sure, just have your POJO implement the ApplicationContextAware interface. It will allow you to have a local reference to the app context files. Page 143 of Rob Harrop's Pro Spring book, or just google the interface name above for examples.

      Glen
      But in my case I am trying to access a bean from within a JSF action controller bean I have written. My controller extends a base class (BaseController) which implements ApplicationContextAware. However when I try to access the applicationContext from within my action code in my subclass it is null and I get a NullPointerException. Do I need to do something else besides just implement the interface? Do I need to add something special to my applicationContext.xml? Again I am using MyFaces with Spring.

      Comment


      • #4
        I have not done this before, but I believe you will also need to add your action controller bean to your applicationContext.xml file, so Spring can identify it and call the setApplicationContext() method from the ApplicationContextAware interface. I believe the action controller bean being used will also need to be instantiated by Spring. Hopefully others more knowledgable on this issue can give you better information.

        Glen

        Comment

        Working...
        X