|
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
|
|
From: Lynette K. <kn...@si...> - 2004-12-21 06:51:12
|
Jeremy Haile <jhaile <at> fastmail.fm> writes:
>
> 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.ap
plyPropertyValues(AbstractAutowireCapableBeanFactory.java:797)
> at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.po
pulateBean(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/
>
I'm also hitting the same error.
<Dec 21, 2004 2:24:51 PM GMT+08:00> <Error> <HTTP> <BEA-101216>
<Servlet: "context" failed to preload on startup in Web application: "Crips".
javax.servlet.ServletException: Error creating bean with name 'exam' defined
in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting
property values; nested exception is
org.springframework.beans.NotWritablePropertyException: Invalid
property 'marksDAO' of bean class [school.eng.electronics.business.ExamImpl]:
Property 'marksDAO' is not writable
at weblogic.servlet.internal.ServletStubImpl.createServlet
(ServletStubImpl.java:884)
at weblogic.servlet.internal.ServletStubImpl.createInstances
(ServletStubImpl.java:848)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet
(ServletStubImpl.java:787)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet
(WebAppServletContext.java:3252)
at weblogic.servlet.internal.WebAppServletContext.preloadServlets
(WebAppServletContext.java:3209)
at weblogic.servlet.internal.WebAppServletContext.preloadServlets
(WebAppServletContext.java:3195)
at weblogic.servlet.internal.WebAppServletContext.preloadResources
(WebAppServletContext.java:3174)
at weblogic.servlet.internal.WebAppServletContext.setStarted
(WebAppServletContext.java:5647)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:869)
at weblogic.j2ee.J2EEApplicationContainer.start
(J2EEApplicationContainer.java:2022)
at weblogic.j2ee.J2EEApplicationContainer.activate
(J2EEApplicationContainer.java:2063)
at
weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateCo
ntainer(SlaveDeployer.java:2592)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit
(SlaveDeployer.java:2515)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit
(SlaveDeployer.java:2317)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit
(SlaveDeployer.java:2399)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare
(SlaveDeployer.java:2311)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare
(SlaveDeployer.java:2479)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask
(SlaveDeployer.java:798)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta
(SlaveDeployer.java:507)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate
(SlaveDeployer.java:465)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute
(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
>
As stated in Spring documentation, the getter method is not required for
spring, and I only set this property.
I did not hit the NotWritablePropertyException with only 1 DAO, ie. if I only
have MarksDAO in ExamImpl, I do not have such an exception.
[ExamImpl.java]
private MarksDAO marksDAO;
private SADAO saDAO;
public void setMarksDAO(MarksDAO marksDAO) {
this.marksDAO = marksDAO;
}
public void setSADAO(SADAO saDAO) {
this.saDAO = saDAO;
}
....
[applicationContext.xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD
BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="exam" class="school.eng.electronics.business.ExamImpl">
<property name="marksDAO"><ref bean="marksDAO"/></property>
<property name="saDAO"><ref bean="saDAO"/></property>
</bean>
<bean id="marksDAO" class="school.eng.electronics.dao.TestMarksDAO"/>
<bean id="saDAO" class="school.eng.electronics.dao.TestSADAO"/>
</beans>
[MarksDAO.java]
public interface MarksDAO {
...
}
[TestMarksDAO.java]
public class TestMarksDAO implements MarksDAO {
...
}
As mentioned above, as spring does not require a getter method and I do not
have a getter method, why do I have such an exception thrown when I try to
deploy my war file??
Thank you.
|