I am learning Spring and am working on a unit test, with the beans being specified in an XML config file. I am wondering how I tell it to use a file on the file system.
The following code* will run:
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("beans.xml")
public class CDPlayerTest {
...
}
The beans.xml file is in the same package as the test class.
But when using
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/Users/pabernathy/pworkspace/springtraining/beans.xml")
public class CDPlayerTest {
...
}
It gives me this error message:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Users/pabernathy/pworkspace/springtraining/beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Users/pabernathy/pworkspace/springtraining/beans.xml] cannot be opened because it does not exist
I can assure you, the file does exist.
Does anyone know how to specify an arbitrary XML file for the Spring beans?
*based on the example in chapter 2 of Spring in Action