title: OpenEntityManagerInViewFilter not working - Spring MVC
body: <p>Ok, so I am once again going nuts trying to solve the OpenEntityManagerInViewFilter problem.</p>
  
  <p>I have looked around a bunch, read a lot of the other questions (that this might seem like a duplicate of) but no joy so far.</p>
  
  <p>So here's the deal: Spring4, XML based web.xml but java vconfig for the rest of my app context setup. I thought it might be related to this solution: <a href="https://stackoverflow.com/a/7015927/258813">https://stackoverflow.com/a/7015927/258813</a> (the ContextLoadListener and the servlet config both loading the app contexts), however, I have ensured that they both explicitly reference different configuration files.  I have also previously had problems when different config files were @ComponentScan-ing the same locations so the context was loaded twice, but that is not the case either.</p>
  
  <p>Web.xml (relevant bits)</p>
  
  <pre><code>&lt;servlet&gt;
          &lt;servlet-name&gt;webapp&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;contextClass&lt;/param-name&gt;
              &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;com.tmm.frm.configuration.WebMvcConfiguration&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/servlet&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextClass&lt;/param-name&gt;
      &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          com.tmm.frm.configuration.ApiSecurityConfig
          com.tmm.frm.configuration.ApplicationContextConfiguration
          com.tmm.frm.configuration.WebSecurityConfig
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>The security configs are both just standard WebSecurityConfigurerAdapter extensions, no other scanning/context jazz.</p>
  
  <p>WebMvc config:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan("com.tmm.frm.controller")
  public class WebMvcConfiguration extends WebMvcConfigurerAdapter{
  </code></pre>
  
  <p>App Context Config (persistence stuff etc)</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement(mode = AdviceMode.ASPECTJ, proxyTargetClass = true)
  @ComponentScan({"com.tmm.frm.service", "com.tmm.frm.helper","com.tmm.frm.core.dao", "com.tmm.frm.security"})
  @PropertySource("classpath:META-INF/spring/database.properties")
  @EnableAspectJAutoProxy(proxyTargetClass = true)
  public class ApplicationContextConfiguration {
  </code></pre>
  
  <p>So both the relevant config classes are specifically defining different packages etc. Web.xml names configs to load by name so neither config classes are being loaded twice.</p>
  
  <p>Then, I hit the controller - I load the user profile from the Secuirty Context (in the controller), then I jsut try to loop through a collection on the UserProfile that is lazily loaded - I would expect the OpenEntityManagerInViewFilter to kick in and load the collection (as a session is still open) but I get the normal can't load lazy object error. The logs clearly states that the filter is called, so I assume somewhere there are two contexts - any one suggest where the rogue context might be?</p>