Testing with Spring and Maven: applicationContext Testing with Spring and Maven: applicationContext spring spring

Testing with Spring and Maven: applicationContext


I think Maven simply didn't include the XML file from main/resources.

You could try to specify explicitly what to include in the pom.xml.

Let me know if the following configuration has worked:

    <!-- Add this directly after the <build>-opening tag -->    <resources>        <resource>            <filtering>true</filtering>            <directory>src/test/resources</directory>            <includes>                <include>**/*.properties</include>            </includes>            <excludes>                <exclude>**/*local.properties</exclude>            </excludes>        </resource>        <resource>            <directory>src/main/resources</directory>            <includes>                <include>**/*.properties</include>                <include>**/*.xml</include>            </includes>        </resource>    </resources>

This is something I use in your case. You can edit this if you don't have properties files to be included.


My test context file is under src\test\resources\spring folder.I managed to load the context with

@ContextConfiguration(locations={"classpath:**/test-context.xml"})

But reference (in test-context.xml) to the application-context.xml which is under src\main\resources\spring folder failed

I managed to load the application-context by creating a ClassPathXmlApplicationContext in the test class with

ClassPathXmlApplicationContext appContext=new ClassPathXmlApplicationContext(new String[]{"classpath:spring/application-context.xml","classpath:spring/model-context.xml"});

Let me know if this helps or might create any other issues.


your application context must be included in classpath and put * :

@ContextConfiguration(locations = { "classpath:*/application-context.xml" })