wood burning stoves 2.0*
The moose likes Spring and the fly likes Bean definition found but not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Bean definition found but not found" Watch "Bean definition found but not found" New topic
Author

Bean definition found but not found

Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

I am not sure whether this is the right section for my question because I am not sure what is happening.

I have a project using Spring that gives some very confusing output. When I run the project in NetBeans with Maven it outputs

Which sound like it has read and understood my bean definitions in spring-config.xml.

The next line then has me somewhat confused

Suddenly it cannot find spring-config.xml, but it has just read the file without problems.

Looking at the complete stacktrace indicates that it is the second of these two lines that cause the exception, and I suspect that it is the first the loads the file without problems.


Can anybody explain to me what is happening here?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

Philip Grove wrote:

Which sound like it has read and understood my bean definitions in spring-config.xml.

No.. Spring is just telling you that, it is trying to load the xml bean definitions from the file, which you have specified as it's present in classpath..
In the next line, it tells you that it can't read the file, because its not present..
Nothing confusing here, its pretty straight forward..
Where you have placed your spring-config.xml file... ?
Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

The spring-config.xml has been placed by NetBeans in the folder containing the source of main package. It's in the folder src/main/java/dk/evorg/game under the project folder.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

then you should be giving new ClassPathResource("dk/evorg/game/spring-config.xml"); If you just give spring-config.xml, it expects to be in the default package.
Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

That results in exactly the same error message.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

Can you just take that xml file and put in the default package and check?
Philip Grove
Ranch Hand

Joined: Aug 18, 2009
Posts: 68

The same file in the default package works just fine. It just might stay in the default folder because it makes sense to me that a configuration file is located in src/main/resources.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Philip Grove wrote:The same file in the default package works just fine. It just might stay in the default folder because it makes sense to me that a configuration file is located in src/main/resources.


Yes, I agree it makes more sense. I always put my config files in the root of the classpath, and maven copies anything in the resources directory to the classpath.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Larsen Raja
Ranch Hand

Joined: Nov 28, 2011
Posts: 58
Am having the same issue.

This is my first spring

INFO - Loading XML bean definitions from class path resource [carDemo-beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [carDemo-beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [carDemo-beans.xml] cannot be opened because it does not exist.


I see the above message in console. But I have initially created carDemo-beans.xml, placed in the package com/vehicles. Since I ws getting the above msg I have added the beans xml file to class path
by using add to build path option. After doing this, xml file was present at the referenced libraries section. Still I get the same error.

Regards
Larsen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean definition found but not found