• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My question is similar to https://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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic