I was trying to run a spring program with different style. I am new to this framework.

I tried to load configuration file with types of loader. like

(1) BeanFactory factory = new XmlBeanFactory(new FileSystemResource("spring.xml"));
		
(2) ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

(3) ApplicationContext context = new FileSystemXmlApplicationContext("/spring.xml");

But in second, I am getting exception that filenotfound.
And same thing i am doing in web application. In my web application configuration file is located exactly in WEB-INF folder. So i could load it as follow.

ApplicationContext context = new ClassPathXmlApplicationContext("/WEB-INF/application-context.xml");

Please give me suggestion. Please be specific with reason.

> But in second, I am getting exception that filenotfound.

Because the file "spring.xml" is not present at the root of the class path; you need to state the hierarchy or the path to your config file from the classpath root.

> In my web application configuration file is located exactly in WEB-INF folder

I couldn't find any statement in the servlet specification which said that the entire WEB-INF folder is added to the classpath; the servlet specification states that:

The contents of the WEB-INF directory are:
• The /WEB-INF/web.xml deployment descriptor.
• The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.
• The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to theWeb application. TheWeb application class loader must be able to load classes from any of these archive files.

TheWeb application class loader must load classes from the WEB-INF/ classes directory first, and then from library JARs in the WEB-INF/lib directory.

Given the above excerpt, just ensure that your application context file lies inside the folder "classes" and it should work out fine.

Edited 7 Years Ago by ~s.o.s~: n/a

Hey thanks for reply. But I think I could not explain my problem exactly. I am getting error in

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

Your answer have been very helpful.

This question has already been answered. Start a new discussion instead.