title: How to Setup web application context in Spring MVC test
body: <p>We have a clear abstraction between Service layers &amp; view layers context configurations and we are loading them as shown below.</p>
  
  <pre><code>Root application context:
  
  &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;classpath*:META-INF/spring/applicationContext*.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  Web application context:
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;lovemytasks&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/mmapp-servlet.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>Now we are trying to introduce SPRING MVC TEST FRAMEWORK to test our application.</p>
  
  <p>For this i would need to setup the same environment as my real web application works.</p>
  
  <p>How can i do that ?</p>
  
  <p>I tried below configuration on my test to load both the contexts. </p>
  
  <pre><code>@ContextConfiguration(locations = { "classpath*:META-INF/spring/applicationContext*.xml",
      "file:src/main/webapp/WEB-INF/spring/mmapp-servlet.xml" })
  </code></pre>
  
  <p>But its erroring out saying </p>
  
  <pre><code>Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Duplicate &lt;global-method-security&gt; detected. 
  </code></pre>
  
  <p>We have defined global security in both root application context and web application context.</p>
  
  <p><strong>Note: The above said issue will not appear when i run my web application. It happens only when i run Spring MVc test</strong></p>
  
  <p>I tried removing my global security and one place and then landing into errors with conversion services on running my tests. Which warned me that I am not loading the context as teh real Spring application does.</p>
  
  <p>Now, i would like to setup my Spring MVC test environment to use or work as the same way my spring web application environment works. Can any one please suggest how can i achieve it ?</p>