Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short answer</strong></p> <p>Remove the <em>/WEB-INF/myapp-servlet.xml</em> from the contextConfigLocation context param.</p> <p><strong>Long Answer</strong></p> <p>The <em>ContextLoaderListener</em> creates a root application context based on the configuration files defined in the contextConfigLocation and loads it into the ServletContext before any Servlet is initialized.</p> <p>The DispatcherServlet at the same time, will create a child application context with the specified configuration. You are not explicitly specifying any bean definition file, so by convention it will take /WEB-INF/appName-servlet.xml (/WEB-INF/myapp-servlet.xml in your case, which by chance exists). It happens that both your root application context and your child application context will have some common beans (duplicates, because they load the same configuration file). </p> <p>You have two options:</p> <p>1) Remove the /WEB-INF/myapp-servlet.xml from the contextConfigLocation. Additionally, if you want to be more explicit, add the configuration to the ServletDispatcher declaration:</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;myapp&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/myapp-servlet.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;myapp&lt;/servlet-name&gt; &lt;url-pattern&gt;*.html&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/myapp-security.xml&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>Note: the beans configured in myapp-servlet.xml will only be visible by the child application context, in case you want to access them from the root application context use the option 2 or reorganize your configuration files.</p> <p>2) Load all the beans in the root application context (your current configuration), and add en empty configuration parameter in the dispatcher servlet. </p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;myapp&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;&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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