applicationContext not found - Spring-Hibernate

Hi there

I'm using WebWork with Spring and Hibernate . IDE netbeans.

My Hibernate properties are in the applicationContext.xml that is placed just under the WEB-INF.

When I try to call the:

new ClassPathXmlApplicationContext("applicationContext.xml");

or

new ClassPathXmlApplicationContext

("/WEB-INF/applicationContext.xml");

(I call it from one of the src packages)

I get an error:

"class path resource [applicationContext.xml] cannot be opened because it does not exist"

The confusing thing is, that sometimes after I change it, move it and try some solutions, when I put it back to the original place, it suddenly works. But then again sometime after I add some files and data not connected to it, it gives me the same error again.

Can you please suggest what could be the issue here? ((-:

Thanks and have a great day,

Dror (-:

[927 byte] By [drorasta555a] at [2007-10-3 4:31:13]
# 1
WEB-INF is not in the CLASSPATH of a web app, but WEB-INF/classes is.%
duffymoa at 2007-7-14 22:34:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Thanks duffymo

When I move the applicationContext.xml under WEB-INF/classes I get an error that Spring is looking for it as "/WEB-INF/applicationContext" and that the file is not found.

When I put it under the WEB-INF, Spring finds it.

I'm just trying to use the default place where the applicationContext should be found automatically.

thanks

Dror (-:

drorasta555a at 2007-7-14 22:34:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

I managed to solve the problem:

1.changed the name of applicationContext.xml to applicationContext-hibernate.xml

2.Moved it to the src folder

3.added this in the web.xml:

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/applicationContext-*.xml</param-value>

</context-param>

4.called:

new ClassPathXmlApplicationContext("/applicationContext-hibernate.xml");

Thanks Duffi for your hint

Dror (-:

drorasta555a at 2007-7-14 22:34:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

spring expects to find the app context for the web tier in WEB-INF, but if you partition your app context into several files you have to tell Spring where to find them.

A better solution than the ClassPathXmlApplicationContext might be the Context LoaderServlet or ContextLoaderListener.That will make sure that the app context is loaded before anything else, and you can tell Spring to look in the same place for the other app context files.

%

duffymoa at 2007-7-14 22:34:36 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
Thanks Duffymo
drorasta555a at 2007-7-14 22:34:36 > top of Java-index,Other Topics,Patterns & OO Design...