This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using properties file for defining class dependency

 
Tai Kings
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Spring 3.0.5, why are you using the older BeanFactory class instead of using ApplicationContext?

Mark
 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic