The following versions were used in this post:

Suppose we have a Java Spring-framework based project named “zoo-app”, which has unit tests and integration tests in its app module.


  public class ZooApp {
      public static void main(String[] args) {

Now, we want to extract the integration tests from “zoo-app” into a separate module, named “zoo-integrationtests” and still use the from “zoo-app”.

By default, the test searches for properties in its own module (“zoo-integrationtests”*), which will be the file and not the file from the tested module (“zoo-app”).


Given this situation, the solution to use the file and the properties contained in the integration test is the simple addition of initializers = ConfigFileApplicationContextInitializer.class in the @ContextConfiguration annotation of the Test class:

  initializers = ConfigFileApplicationContextInitializer.class,
  classes = {ZooApp.class})
public class ZooAppIntegrationTest {

  public void testZooAppIntegration() {
    // some integration tests here

With this class referenced in the @ContextConfiguration, the integration test uses the file from the application referenced in the classes field, in this case only “ZooApp”.

Answer also featured on stackoverflow: link1 link2.