|
From: <jue...@we...> - 2004-12-06 21:37:38
|
I've just changed NotWritablePropertyException's error message to "Bean =
property 'myProperty' is not writable or has an invalid setter method: =
Does the parameter type of the setter match the return type of the =
getter?", which should give an indication of what could be wrong. =
Similar for NotReadablePropertyException.
=20
Thanks for raising this issue!
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von j=FCrgen h=F6ller [werk3AT]
Gesendet: Mo 06.12.2004 22:33
An: spr...@li...
Betreff: Re: [Springframework-developer] Confusing =
NotWritablePropertyException for invalid bean property
The information about bean property setters and getters actually comes =
from the JDK's JavaBeans Introspector. I assume that in case like yours, =
the introspector doesn't detect a correctly matching setter for the =
getter and thus marks the property as "not writable". I see that the =
resulting error message is somewhat misleading, though...
Juergen
________________________________
Von: spr...@li... im Auftrag =
von Jeremy Haile
Gesendet: Mo 06.12.2004 22:26
An: spr...@li...
Betreff: [Springframework-developer] Confusing =
NotWritablePropertyException for invalid bean property
I have had an issue where a spring configured property is "set" with a
more specific type than the getter-method returns. The reason is that
the getter method implements an interface and is required to return a
specific type. The net result is that the getter and setter method take
in/return different class types. My getter and setter looked like the
code below:
public Component getView() {
return view;
}
public void setView( Container view ) {
this.view =3D view;
}
This is probably not legal, JavaBeans style access, and my solution
ended up being renaming the method in the interface. However, the error
message I received was confusing at best, since the property "view" is
obviously writeable based on the code pasted above. The error message
was:
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'alarmBanner' defined in class path resource
[default.dynapp.spring.xml]: Error setting property values; nested
exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'view' of bean class [AlarmBannerController]: Property
'view' is not writable
org.springframework.beans.NotWritablePropertyException: Invalid property
'view' of bean class [AlarmBannerController]: Property 'view' is not
writable
at =
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImp=
l.java:666)
at =
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImp=
l.java:588)
at =
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImp=
l.java:720)
at =
org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperIm=
pl.java:747)
at =
org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperIm=
pl.java:736)
at =
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact=
ory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:797)
at =
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFact=
ory.populateBean(AbstractAutowireCapableBeanFactory.java:637)
The getter was not even required for spring, as I only set this
property.
I have two questions:
1) Is this behavior desirable? Should Spring throw an exception if the
getter and setter's class type does not match. This is probably not
really valid JavaBean-style properties, but obviously you can still get
and set the "view" property. In my case, I was not even "getting" the
property using spring, but only setting it.
2) If this is the desired behavior, should the error message displayed
be clearer? I have seen this error in the past and it usually means
that there is no setter method or the setter method had non-public
access. It seems like this error message should read more like
"Property 'view' is not a valid bean property." - or something like
that.
Jeremy Haile
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|