This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist" Watch "Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist" New topic
Author

Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist

R Bab
Greenhorn

Joined: Jan 19, 2006
Posts: 3
Hi,
My question is similar to http://www.coderanch.com/t/424153/Spring/Application-Frameworks/beans-xml-cannot-opened-because

I kinda know the answer in one way but still could not figure out the way I expect

I have folder structure as follows.

project->src->java
com.x.y.Hello.java
project->src->conf
beans.xml

Code looks like,



Exception:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [conf/beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [conf/beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)


So I have tried few other combinations:


but nothing works.

So I have changed the folder structure to

project->src->
com.x.y.Hello.java
project->src->
beans.xml

ofcourse everything works!

But I do not want to compromise the folder structure.

1) So how to add conf/beans.xml into the classpath so that ClassPathXmlApplicationContext can resolve it.

2) Also how do I find out list of class paths loaded by ClassPathXmlApplicationContext?

I use spring 2.5.x and I thought I will use like,



Now I run into
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hello' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)

3) If I see the above error that means the beans.xml is found but not the bean 'hello' correct? If so, how to resolve this?

Any help is appreciated. Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Larry Chung
Ranch Hand

Joined: Feb 02, 2010
Posts: 247
I can help with question 1 at least.

Notice that in your project tree folder structure, there is a folder called "config":
R Bab wrote:
project->src->java
com.x.y.Hello.java
project->src->config
beans.xml


For your code to work, the folder's name should be refactored to "conf". Be sure to put beans.xml in the conf folder.


SCJP 6
R Bab
Greenhorn

Joined: Jan 19, 2006
Posts: 3
Thanks for your reply. That was my bad and I made the typo while posting. In the actual code I still refer the dir as conf


Larry Chung wrote:I can help with question 1 at least.

Notice that in your project tree folder structure, there is a folder called "config":
R Bab wrote:
project->src->java
com.x.y.Hello.java
project->src->config
beans.xml


For your code to work, the folder's name should be refactored to "conf". Be sure to put beans.xml in the conf folder.


Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

1) So how to add conf/beans.xml into the classpath so that ClassPathXmlApplicationContext can resolve it.

If you are using the command line to execute your application, you have to add the project/src directory in the CLASSPATH. If you don't know how to, check this.
If you are using an IDE, like Eclipse or IntelliJ, you have to configure the execution properties of your application. So what are you using ? The command line or an editor ?


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classpath issue: class path resource [beans.xml] cannot be opened because it does not exist
 
Similar Threads
Spring - ClassPathXmlApplicationContext not able to load the XML file
Problem in code
[beans.xml] cannot be opened because it does not exist
Hi
FileNotFoundException