1

I am working on web app and I use Spring MVC. It has one servlet. So if I am right, it is supposed to have one root application context and additional application context for that servlet. Beans in servlet application context can access beans in root application context. However, let's say app started, and I want to add some beans to root application context, how should I proceed? Basically, I have some bean configs in "additional-beans.xml". I want to add them to root application context but not at init point, but some time after the web app has started. How to do that? Seems like doing something like

AbstractApplicationContext rootContext = new ClassPathXmlApplicationContext(new String[]{"additional-beans.xml"});

withing one of my controllers will not add additional beans to the root application context. But then, where are they added? Is it even possible? THanks)

Russell'sTeapot
  • 373
  • 2
  • 11
  • 21

1 Answers1

0

You can use Lazy init beans

<bean id="myBean" class="net.spring.ioc.MyBean"
        lazy-init="true" />

PS: My suggestion is to use WebApplicationContext

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
                      org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

http://www.mkyong.com/spring3/spring-3-mvc-hello-world-example/

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
  • thanks ) but I cannot do that. additional-beans.xml might be changed after the has started. So I wanna change the content of the file and then load it programmatically – Russell'sTeapot Apr 19 '13 at 06:35
  • Maybe this is helpfull http://stackoverflow.com/questions/797894/dynamically-change-spring-beans – Evgeni Dimitrov Apr 19 '13 at 07:06