File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes How to inject TreeMap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to inject TreeMap?" Watch "How to inject TreeMap?" New topic

How to inject TreeMap?

Kamil Kuchta

Joined: Mar 09, 2009
Posts: 17
How to inject TreeMap?
This map is fulfill in the application.
My beans

And setter in class House

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'house' defined in file [snowWhiteBeans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'dwarfs' of bean class []: Bean property 'dwarfs' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

And what with generic data information Map<String, Dwarf>? Should bean contain this generic information?
Vivek K Singh
Ranch Hand

Joined: Dec 22, 2009
Posts: 85

It should work, Try this:

And write the context as.

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Is your setter method in the correct House class ? (

[My Blog]
All roads lead to JavaRanch
Kamil Kuchta

Joined: Mar 09, 2009
Posts: 17
It turns out that I already had a getter getDwarfs() which returns a length of collection. When I changed bean name from dwarfs to dwarfsMap (and setter name setDwarfsMap) it started work. I think that that getter was a reason of my problems
I agree. Here's the link:
subject: How to inject TreeMap?
It's not a secret anymore!