Results 1 to 3 of 3

Thread: How to correctly access ApplicationContext after it's been initialized?

  1. #1
    Join Date
    Jul 2009
    Posts
    9

    Question How to correctly access ApplicationContext after it's been initialized?

    I'm quite new to Spring so sorry for the stupid question. For test purposes i've initialized by beans in the following way:

    public static void main(String[] args) {
    Code:
                ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
                Foo f = (Foo) context.getBean("foo");
                f.start();
        }
    And that would work fine, but when it comes to the bigger application what is the correct way to access context object? Do I have to create singleton for that purpose?

  2. #2
    Join Date
    Jun 2009
    Posts
    190

    Default

    You can use ContextConfigListener and mention the files in the context params.

  3. #3
    Join Date
    Jun 2009
    Posts
    190

    Default

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>


    servlet>
    <servlet-name>crmapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/spring_context/web/applicationcontext.xml</param-value>
    </context-param>

    Hope this helps

Posting Permissions

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