Announcement Announcement Module
Collapse
No announcement yet.
Loading Application context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading Application context

    Hi ,
    I had a question that if I load applicationcontext.xml through struts-config.xml and then again in some part of the application I load application context again with command
    Code:
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
    						APPLICATION_CONTEXT_PATH);
    will there be two spring context in the memory or there will only one and the code will load from the same applicationContext loaded by struts-config.xml.

    Thanks ,
    Amol

  • #2
    If you are using Spring and Struts I would have a look at this article.
    http://www-128.ibm.com/developerwork...ary/j-sr2.html

    If you've got a ServletContext instance, then you can use WebApplicationContextUtils. Otherwise there are quite a few options e.g. ApplicationContextAware, WebApplictionContextUtils, SingletonBeanFactoryLocator, ContextSingletonBeanFactoryLocator. Basically you shouldn't be creating another ApplicationContext.

    Comment


    • #3
      Hi karldmoore ,
      Actually I wanted to know that will this load two spring context in memory or will it use the same.

      Thanks
      Amol

      Comment


      • #4
        Originally posted by aamol View Post
        Actually I wanted to know that will this load two spring context in memory or will it use the same.
        Yes you will load another ApplicationContext. Hence the discussion of ways to get hold of the exist one rather than creating a new one.

        Comment


        • #5
          Thanks that answers my doubt.

          Comment


          • #6
            Originally posted by aamol View Post
            Thanks that answers my doubt.
            Not a problem, glad the information was useful. The reference manual does has some information on this if you are interested, along with details of the techniques I talked about earlier.

            Comment

            Working...
            X