Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
R Bab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
R Bab
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic