No write method for property问题的解决

来源:互联网 发布:手机大数据是什么意思 编辑:程序博客网 时间:2024/05/22 13:24

public class Event {private String eventid;private String eventname;
<span style="white-space:pre"></span>//0,1private String type;public String getEventid() {return eventid;}public void setEventid(String eventid) {this.eventid = eventid;}public String getEventname() {return eventname;}public void setEventname(String eventname) {this.eventname = eventname;}public String getType() {return type;}public void setType(String type) {this.type = type;}
<span style="white-space:pre"></span>
<span style="white-space:pre"></span>public int <span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; white-space: pre; background-color: rgb(250, 250, 250);">getTypeInt(){</span>
<span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; white-space: pre; background-color: rgb(250, 250, 250);"><span style="white-space:pre"><span class="keyword" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; white-space: pre; background-color: rgb(250, 250, 250); color: rgb(127, 0, 85); font-weight: bold;">return</span><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; white-space: pre; background-color: rgb(250, 250, 250);"> Integer.parseInt(type);</span></span></span>
<span style="background-color: rgb(250, 250, 250); font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px;"><span style="white-space:pre"></span>}</span>
</pre><pre name="code" class="html"><span style="white-space:pre"></span>
}


使用xfire的websevice调用时,会将对象与xml进行捆绑。整体的大概流程是:

1、 通过传递对象的get、is方法获取需要传递的属性(属性私有)

2、 与xml捆绑并网络传输

3、 解绑参数,并调用set方法将参数设置进去。

 

因此,虽然getTypeInt()只是一个方法,还是会被误以为是属性并与xml进行捆绑,在客户端当做属性进行解绑,并调用setTypeInt进行设置时,发现没有该方法,就跑出了一个异常。

 

 

在不改动源代码的情况下,我们在使用xfire中就得绕过这个坑:

1、如果你需要传递某些属性,一定要同时定义它的get、set方法,否则会丢失这些信息

2、自定义的方法名不要使用get打头的方法名,否则会被识别为属性并调用set设值,这样就会抛错了

解决办法:现在只需要将确实的属性和方法,补充上去就可以了。

这是我遇到的问题,以及解决办法,希望对大家有所帮助

0 0
原创粉丝点击