• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean definition found but not found

 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 667
4
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 667
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That results in exactly the same error message.
 
Prasad Krishnegowda
Ranch Hand
Posts: 667
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you just take that xml file and put in the default package and check?
 
Philip Grove
Ranch Hand
Posts: 68
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Larsen Raja
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic