April
April

Reputation: 137

Class path resource not found randomly

We have integrated Spring with Hibernate and Struts2 in Eclipse and have been getting these errors when running the build:

14-Oct-2011 10:37:27 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...
Caused by: java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...

Our mapping in applicationContext.xml is:

<property name="mappingResources" value="Test.hbm.xml" />

Test.hbm.xml is in /build/classes, and we have tried putting it in /WEB-INF, /src, and even created a new source folder called /hibernate and dumped it in and it worked on only a few machines.

The first time we wrote it, it showed this error. And then we copied the exact same code into a new project, it suddenly worked. On some machines, it works; on others, it shows this error.

Does anyone know what could be wrong? Let me know if any other information is needed.

Thanks so much.

Upvotes: 0

Views: 2113

Answers (1)

Ryan Stewart
Ryan Stewart

Reputation: 128809

That's not a build-time error. It's a run-time one. Intermittent failures of that sort indicate a problem with your build, though. As a classpath resource, Test.hbm.xml must be in a classpath location when you run your app. Where exactly that is depends on how you're running it, but /WEB-INF will never work for a webapp, and a random /hibernate folder is unlikely to work, too, unless you've done some custom configuration to make that a classpath resource or make it build to one. For a more definitive answer, you'll need to provide more detail about what you're running and how you're building it.

Upvotes: 1

Related Questions