0

I build a library (a bounch of classes) that uses spring library and a context-application.xml file (to parse REST response using Marshalling).

At this point I included the jar on my project and I'm trying to call one of this classes, but it's telling me that context-application.xml file is missing.

I'm trying to load the application context using :

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");

It's not so clear (I'm a newbie in Spring framework) where to put this file used by my jar.

Is it possible? Could anyone help me?

1
  • Solved: ApplicationContext applicationContext = new ClassPathXmlApplicationContext("com/kipcast/dataModel/drugs/alfresco-context.xml"); Commented Dec 4, 2011 at 11:42

2 Answers 2

2

It needs to be in the root of your CLASSPATH. In your case - the root directory of the JAR file. If you are using maven - it is the /src/main/resources folder.

Sign up to request clarification or add additional context in comments.

Comments

1

If I understand correctly you want to use an XML from jar file that is outside of your jar and in the main project that contains the jar file? If so then it is not really a good practice as in this case your jar file will be dependent of the application therefore wont be really redistributable, so what is the point of having a jar file at all? If you look at the CXF JAX-RS implementation it is a good example of how to solve it nicely. It has a rather opposite approach. CXF has a number of it's own spring xml files inside that needs to be included from the main webapp like this.

  <import resource="classpath:META-INF/cxf/cxf.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

that way you can define your main webapp classes and your jar classes in the same XML file. A complete example is here:

http://cxf.apache.org/docs/jax-rs.html#JAX-RS-JAXRSandSpringAOP

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.