|
From: Jeremy H. <jh...@fa...> - 2004-12-06 21:27:04
|
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 = 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(BeanWrapperImpl.java:666)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:588)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:720)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:747)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:736)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:797)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.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
|