java webservice wsdl 启动报错

yalitaida123 2015-10-08 01:01:40
java代码如下:
package com.erdb.service;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class ServiceHello {
/**
* 生成客户端:
* wsimport -s E:\\GDHT_SOFTWARE\\中核设备可靠性数据库\\田湾项目\\SAP接口研发\\project\\TheClient\\src -p com.erdb.client -keep http://localhost:9001/Service/ServiceHello?wsdl
* 供客户端调用的方法
* @param name 传入参数
* @return List 返回结果
*/
public List<Student> getValue(String name){
// System.out.println(name);
// List<String> arrayString = new ArrayList<String>();
// arrayString.add("姓名:" + name);
// arrayString.add("性别:男");
// arrayString.add("年龄:25");
List<Student> arrayString = new ArrayList<Student>();
return arrayString;
}

// /***
// * @param mapName
// * @param mapObject
// * @return
// */
// public Map<String, Object> getMap(String mapName, String mapObject) {
// Map<String, Object> map = new HashMap<String, Object>();
// map.put(mapName, mapObject);
// return map;
// }

/**
* @param args
*/
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:9001/Service/ServiceHello", new ServiceHello());
System.out.println("service success!");
}
}


package com.erdb.service;

public class Student {

public String name;
public String sex;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}

}


执行的时候控制台报以下错误:
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:156)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:84)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:235)
at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:328)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:190)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:498)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:246)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:170)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:113)
at javax.xml.ws.Endpoint.publish(Endpoint.java:220)
at com.erdb.service.ServiceHello.main(ServiceHello.java:45)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Class has two properties of the same name "name"
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.getName()
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.name
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
Class has two properties of the same name "sex"
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.getSex()
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.sex
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse

at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:143)
... 10 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Class has two properties of the same name "name"
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.getName()
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.name
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
Class has two properties of the same name "sex"
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.getSex()
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse
this problem is related to the following location:
at public java.lang.String com.erdb.service.Student.sex
at com.erdb.service.Student
at public java.util.List com.erdb.service.jaxws.GetValueResponse._return
at com.erdb.service.jaxws.GetValueResponse

at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:451)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:283)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:126)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1148)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:173)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96)
at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:151)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:143)
... 12 more


如果把 List<Student> 改成 List<String> 就没错了。请问为什么?如何解决?
跪求高手解答!!!
...全文
267 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
心随自在飞 2015-10-08
  • 打赏
  • 举报
回复
基础不扎实,属性私有,不然还要set 和get 有什么用!! 多看看基础的学习资料吧!
zhchyun2008 2015-10-08
  • 打赏
  • 举报
回复
我也接点分 我也接点分 我也接点分
zhaoyuanbocq 2015-10-08
  • 打赏
  • 举报
回复
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions Class has two properties of the same name "name" 意思很明显 你有2个类中都定义了public 的name 和 sex变量 所以冲突了 定义成 private 或者 去修改直接一个的名字 建议 用private
夜雨~听风 2015-10-08
  • 打赏
  • 举报
回复
Student class里的全局变量请用private定义
林家小米 2015-10-08
  • 打赏
  • 举报
回复
看你报错提示:是有多组数据
tony4geek 2015-10-08
  • 打赏
  • 举报
回复
http://stackoverflow.com/questions/24366814/spring-jaxb-integration-class-has-two-properties-of-the-same-name

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧