• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using properties file for defining class dependency

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic