Spring Bean BeanCreationException,NotWritablePropertyException异常

来源:互联网 发布:积分编排软件 编辑:程序博客网 时间:2024/05/21 10:18

错误现象

aused by: org.springframework.beans.NotWritablePropertyException:
 Invalid property 'userServiceRemote' of bean class [com.xxx.web.score.ScoreAction]: Bean property 'userServiceRemote' is not writable or has an invalid setter method.
 Does the parameter type of the setter match the return type of the getter?at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:925) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:62) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1489) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:161) ~[xwork-core-2.3.32.jar:2.3.32]at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178) ~[xwork-core-2.3.32.jar:2.3.32]at com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22) ~[xwork-core-2.3.32.jar:2.3.32]at com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148) ~[xwork-core-2.3.32.jar:2.3.32]at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:298) ~[xwork-core-2.3.32.jar:2.3.32]


错误信息一堆,要学会看重点:

Invalid property 'userServiceRemote' of bean class [com.xxx.web.score.ScoreAction]: Bean property 'userServiceRemote' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?翻译下:bean类[com.xxx.web.score.ScoreAction]的属性“userServiceRemote”属性无效:Bean属性“userServiceRemote”不可写或具有无效的setter方法。 setter的参数类型是否匹配getter的返回类型?



错误原因:

        要先说下事情的起因了,类A中需要把类B注入成为private属性,

配置如下:



后来,ScoreAction这个类又不需要userServiceRemote这个属性了,我就把private ......这句注释掉了.

spring配置文件,依然有这句话,我知道.

<property name="userServiceRemote" ref="userServiceRemote" />

但我想,这里声明了属性, 但我不实际使用,应该没有问题, Too young, too simple,


访问时,接口直接提示,服务器异常,  让人摸不着头脑,后来,在本机开发环境,编译,部署,才看到上面的BeanCreationException,NotWritablePropertyException异常

信息.


解决办法

   把ScoreAction类中,private IUserServiceRemote userServiceRemote;删掉,

   把配置文件里的<property name="userServiceRemote" ref="userServiceRemote" />也删掉.


其他说明

1.修改代码后,一定要先在本机开发环境,编译代码,部署项目,启动tomcat,访问接口,试一试, 对自己的代码100%自信,会蒙蔽一些细节错误.

联调换句那一句服务器异常,看我也是摸不着头脑.   


2.当A类不想再使用某个属性B时,把相关配置,引用都删掉,只是注释掉,会行程干扰,


感觉写的不够深入,请见谅.



阅读全文
0 0
原创粉丝点击