my dog learned polymorphism
The moose likes Spring and the fly likes Using properties file for defining class dependency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Using properties file for defining class dependency" Watch "Using properties file for defining class dependency" New topic

Using properties file for defining class dependency

Tai Kings

Joined: Jul 07, 2011
Posts: 1
Hi All,

I am new to Spring, and following the examples of Spring book, but have problem about BeanFactory using Properties file. Please help
- Posted 3 files (complete code) and 1 screen capture about error message.
- Environment : J2SE 6 , spring-framework-3.0.5.RELEASE, Eclipse Java EE IDE for Web Developers.
- FYI, in previous lab example, can successfully use xml configuration file for definiting class dependency, but failed when using property file (non-xml file)

File1 :

File 2 :

File 3 :

Screen capture

Many Many Thanks!


Many Many Thank you.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

If you are using Spring 3.0.5, why are you using the older BeanFactory class instead of using ApplicationContext?


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206

If looked the error message carefully and pay attention to error you'll see that it tell
you clearly that you didn't specified the class name on the bean definition.

For instance,

"Caused by: java.lang.IllegalStateException: No bean class specified on bean definition"

Based on this I error I can tell what' wrong with the code simply in the ""
file you didn't configure it correctly.

File 3 :
helloBean.class=onlyfun.caterpillar.H2 //The problem is specified the wrong bean name.


"H2" is what you need instead of the whole package name prefix the class name.

helloBean.class = H2 //bean is of class H2

Make a change, test it, and let us know if that fix the problem. I can't confirm
100% that will fix the problem unless it being tested.

"Your life is in your hands, to make of it what you choose."
I agree. Here's the link:
subject: Using properties file for defining class dependency
It's not a secret anymore!