Announcement Announcement Module
Collapse
No announcement yet.
Finding an already loaded ApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding an already loaded ApplicationContext

    Hello,

    I'd like to be able to load an applicationContext "on demand" inside a servlet environment. I already have an XmlWebApplicationContex loaded normally and I'd like to be able to set it as the parent of an application context that might be set up while the servlet container is already running e.g.:

    public void run(String springConfigFile){
    ApplicationContext ac = new FileSystemXmlApplicationContext(springConfigFile);
    ac.setParent(parentWebXMLApplicationContext);
    TransactionHandler handler = (TransactionHandler) ac.getBean("transactionHandler");
    handler.handle();
    }

  • #2
    WebApplicationContextUtils

    Hey bknights,

    Have you checked out WebApplicationContextUtils. getWebApplicationContext?

    -Arthur Loder

    Comment


    • #3
      Finding an already loaded ApplicationContext

      Thanks that looks like it will do the trick.

      Comment


      • #4
        Finding an already loaded ApplicationContext

        Actually it's even simpler than that because as I got into the design of this thing I realized I'd still have a dispatcher for the per job application contexts and the dispatcher would be loaded by the root context.

        I just made the dispatcher implement ApplicationContextAware and I no longer have an inappropriate servlet dependency.
        Hence:

        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        parentAppContext= applicationContext;
        }

        public void run(String springConfigFile){
        ApplicationContext ac = new FileSystemXmlApplicationContext(springConfigFile);
        ac.setParent(parentAppContext);
        TransactionHandler handler = (TransactionHandler) ac.getBean("transactionHandler");
        handler.handle();
        }

        Comment

        Working...
        X