I am running a Junit (SpringJUnit4ClassRunner) to access some spring beans in my integration test.
I need to load a few xml files via @ContextConfiguration, those files are deployed by a external approach to my Tomcat directly via a jar file. -- In other words, these files are in:
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar
such as
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar/a.suffix.xml
my_tomcat_home_path/webapps//WEB-INF/lib/external.jar/b.suffix.xml
...
I put Tomcat path into my eclipse classpath, then if I also include the that into my eclipse classpath, then the following code in my JUnit works
@ContextConfiguration(locations = {"classpath:*suffix.xml"})
However, if I don't put that into my eclipse classpath (because the jar file name may change from time to time), then my following code does NOT work (but Tomcat home "" is still in eclipse classpath):
@ContextConfiguration(locations = {"classpath:/webapps/<my_app>/WEB-INF/lib/external.jar/*suffix.xml"})
Could somebody please help me out?
Thanks a lot!!
Additional try -------------------------------
I tried to use the package path inside the jar, instead of using the external.jar itself. The the code looks like the following:
@ContextConfiguration(locations = {"classpath:/webapps/<my_app>/WEB-INF/lib/path_inside_the_external_jar/*suffix.xml"})
In this case, I no longer get "XML not found because file does not exist" problem. Instead, I get the following errors:
Caused by: java.io.FileNotFoundException: class path resource [webapps/my_app/WEB-INF/lib/path_inside_the_external_jar/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:163)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.isJarResource(PathMatchingResourcePatternResolver.java:406)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:338)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:276)
at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1018)
at org.springframework.context.support.GenericApplicationContext.getResources(GenericApplicationContext.java:192)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:177)
... 23 more