David
David

Reputation: 1023

ClassPathXmlApplicationContext reading file outside of JAR

My code instantiates a spring instance using the following code:

String filePath = "applicationContext.xml";
ApplicationContext context = new ClassPathXmlApplicationContext(filePath);

This works if I put a file named "applicationContext.xml" in the root of a jar in my WEB-INF/lib folder. However, I would prefer to have a file named "applicationContext.xml" in my WEB-INF/classes folder. I have tried the following values for filePath and all of them generate a FileNotFoundException:

applicationContext.xml
/webappName/WEB-INF/classes/applicationContext.xml
/WEB-INF/classes/applicationContext.xml
classes/applicationContext.xml

None of these has worked. What is the correct syntax to use with ClassPathXmlApplicationContext to read an xml file out of the WEB-INF/classes folder?

Upvotes: 2

Views: 3009

Answers (2)

user3535778
user3535778

Reputation: 135

Use FileSystemXmlApplicationContext

Upvotes: 1

ndeverge
ndeverge

Reputation: 21564

As commented below, you should try /applicationContext.xml

Upvotes: 2

Related Questions