I have been reading:
http://static.springsource.org/spring/docs/2.5.x/reference/resources.html
But am having difficulty understanding how to specify classpath resource paths. For example I have a project structure as follows in an eclipse spring project:
project1
src
main
resources
maincontext.xml
test
resources
testcontext.xml
java
uk
co
project1
Unittest.java
Then in my testfile I have:
@ContextConfiguration(locations={"classpath:testcontext.xml", "classpath:<path of maincontext>"})
public class BlacklistTest extends AbstractTransactionalJUnit4SpringContextTests{
When I right click on my test file and select debug as JUnit test, the testcontext.xml is found fine. This makes me think the root of my classpath is “project1/src/test/resources”. I do not understand where this is determined in eclipse..? Furthermore once I have done this, how do I include maincontext.xml if it is above my root? And finally if I included another project ‘project 2’ and wanted to add a spring context file from it, how do I reference that in my unittest.java file.
The “root” of your classpath is, literally,
""(an empty string, consider it like a"/"on a filesystem).It looks like you’re using Maven. This means that things like
/src/main/java,/src/main/resources, etc. get merged during the build process–in other words, Eclipse uses each as a source directory. Thetesthierarchy follows suit.You don’t want to include something that is “above” your root–IMO stick to classpath resources. If you don’t, you must name it explicitly, leave off the
"classpath:"prefix, since it isn’t on the classpath, and provide a fully-qualified path (or as fully-qualified as your environment requires, for example, a web-app filename may be based off of the web context root, like"/WEB-INF/foo-context.xml").