File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Using properties file for defining class dependency

Tai Kings
Greenhorn

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 : PropertiesDemo.java


File 2 : H2.java


File 3 : beans-config.properties


Screen capture


Many Many Thanks!

TaiKS


Many Many Thank you.

TaiKS
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
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 "beans-config.properties"
file you didn't configure it correctly.

Problems:
File 3 : beans-config.properties
helloBean.class=onlyfun.caterpillar.H2 //The problem is here...you specified the wrong bean name.
helloBean.helloWord=Welcome!

Solutions:

"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.


OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using properties file for defining class dependency