Booting Spring Context dynamically at runtime in a web application

I am converting a standard Java application that uses Spring Framework in a web application. This application loads a new Spring Context based on the runtime parameters that were executed with ClassPathXmlApplicationContext/FileSystemXmlApplicationContext

.

So my question is how to do the same in a web application, given that I have already configured my web.xml and added Spring Listeners as shown below:

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

      

Another problem, my deployment environment is on Tomcat 5.5 where I cannot see any entries while loading the Spring context to find out what is wrong.

+2


source to share


2 answers


If you really want to load the custom context when you start your web page, you can customize your web.xml with a property placeholder for the context name.



<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:${my_context_file}</param-value>
</context-param>

      

+2


source


To enable logging you may need to set it in your log4j.properties file, for example: log4j.logger.org.springframework = DEBUGGING



You also need to make sure that you are registering with CONSOLE and not some other thread. If you are next, log messages should appear in catalina.out

+1


source







All Articles