title: How to ensure load time weaving takes place for Eclipselink when using SpringBootTest with other tests running beforethe Spring one
body: <p>I'm using Spring Rest Docs to generate documentation for my REST services. This involves running unit(strictly integration) tests that run against a live Spring Boot Container that is kicked off by the test. The test class looks like this:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringBootTest(classes = MySpringConfiguration.class)
  @WebAppConfiguration
  public class ApiDocumentation {
  
    private MockMvc mockMvc;
  
    @Rule
    public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
  
    @Autowired
    private WebApplicationContext context;
  
    @Autowired
    private ObjectMapper objectMapper;
  
    @Before
    public void setUp() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
              .apply(documentationConfiguration(this.restDocumentation))
              .build();
    }
  
  
    @Test
    public void testSomething() throws Exception {
    }
  }
  </code></pre>
  
  <p>The application uses JPA with EclipseLink for the EntityManager implementation. </p>
  
  <p>When I run the test standalone in my IDE or as the only test present when I run a Maven build using the maven-surefire-plugin everything works fine.</p>
  
  <p>However it's not the only test I want to run in the suite. As soon as I run other tests in the suite I come across the issue mentioned <a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/Spring#Common_Issues" rel="nofollow">here</a>, namely </p>
  
  <p>"Spring's agent does not initialize the persistence context until the application accesses the Spring context. If the application has already triggered the loading of the persistent class before accessing the Spring context, weaving will not occur."</p>
  
  <p>and get errors like this:</p>
  
  <p>Exception Description: The method [_persistence_set_someField_vh] or [_persistence_get_someField_vh] is not defined in the object [mypackage.MyEntity].</p>
  
  <p>So what do people normally do to get around this ? Run SpringBootTest classes in a different module to unit tests that access entities ?</p>