Question

I'm trying to load an application context which is inside a jar as a plugin. I use this to load the context:

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**my-context.xml");

When I load the jar through pom.xml, it works fine.

Then I add it directly in the classpath using eclipse instead of maven to avoid to compile every time (ultimate goal is the shared lib folder in tomcat, not working too). Now spring is unable to find it and return a default context (no exception)

I checked that it's correctly insert in the classpath using:

InputStream in1 = this.getClass().getClassLoader().getResourceAsStream("my-context.xml");

It works.

I checked logs. Using the pom.xml, spring is correctly searching in the jar

Searching directory  [...target\classes\META-INF\maven\x.y.z] for files matching pattern [...\x.y.z/target/classes/**/my-context.xml]
Searching directory  [...ehealth.poc.module1] for files matching pattern [D:/JRB/Projects/Vivates/workspaces/default/extcom/ehealth.poc.module1/target/classes/**/ecm-context.xml]
...
Resolved location pattern [classpath*:**/my-context.xml] to resources [file [...\target\classes\my-context.xml]]
Loading XML bean definitions from file [...\target\classes\my-context.xml]
...

In the second case, nothing in the log about my jar.

Why spring does not have the same behavior when I use maven or directly the classpath? I maven doing something else than simple adding dependencies location in the classpath?

Was it helpful?

Solution

Finally, we found the solution on eclipse.

The problem comes from the ** in

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**my-context.xml");

It looks like ** doesn't scan the .jar files. Setting the direct path is working :

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:my-context.xml");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top