views:

30

answers:

1

I have a WAR project and I am trying to store spring configuration files within the /WebContent/WEB-INF/Spring/ folder (as required by my employer), but when I do that I have not found a way to be able to reference those files within my junit tests. I was told today that I can modify my MANIFEST.MF file so that the spring configuration files are included, but I have not been able to successfully reference the files from the manifest file.

My first question is whether or not it is possible to reference files in the /WebContent/WEB-INF/Spring/ folder from my junits? If it is possible, how to the manifest file know where to look for the files? Are the links relative?

The folder structure for my WAR is as follows (structure is defined by the company I work for):

WARProject
 - src\
 - WebContent\
 - - WEB-INF\
 - - - Spring\
 - - - - App-config.xml
 - - - - Security.xml
 - - META-INF\
 - - - MANIFEST.MF

I appreciate any guidance you can provide.

Jeremy

A: 

If you are using Spring 2.5 or later and Spring's TestContext framework, then you can simply annotate the test class with @ContextConfiguration(locations = {path/to/file})

If you are loading an ApplicationContext yourself, then just make sure that /WebContent/WEB-INF/Spring/ is on the classpath and load the file with classpath:contextname.xml.

matt b