Note that there are some explanatory texts on larger screens.

plurals
  1. POContextLoaderListener or not?
    primarykey
    data
    text
    <p>A standard spring web application (created by Roo or "Spring MVC Project" Template) create a web.xml with <code>ContextLoaderListener</code> and <code>DispatcherServlet</code>. <strong>Why do they not only use the <code>DispatcherServlet</code> and make it to load the complete configuration?</strong></p> <p>I understand that the ContextLoaderListener should be used to load the stuff that is not web relevant and the DispatcherServlet is used to load the web relevant stuff (Controllers,...). And this result in two contexts: a parent and a child context.</p> <p>Background:</p> <p>I was doing it this standard way for several years.</p> <pre class="lang-xml prettyprint-override"><code>&lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath*:META-INF/spring/applicationContext*.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- Handles Spring requests --&gt; &lt;servlet&gt; &lt;servlet-name&gt;roo&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;WEB-INF/spring/webmvc-config.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; </code></pre> <p>This often caused problems with the two contexts and the dependencies between them. In the past I was always able to find a solution, and I have the strong feeling that this makes the software structure/architecture always better. But now I am facing a <a href="https://stackoverflow.com/questions/8534222/how-to-bridge-spring-application-context-events-to-an-other-context">problem with the events of the both contexts</a>. </p> <p>-- However this makes my rethink this two context pattern, and I am asking myself: why should I bring myself into this trouble, why not loading all spring configuration files with one <code>DispatcherServlet</code> and removing the <code>ContextLoaderListener</code> completely. (I still will to have different configuration files, but only one context.)</p> <p>Is there any reason not to remove the <code>ContextLoaderListener</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload