Webshpere上发布 JAVA 中使用CXF配置WebService Caused by: java.lang.ClassCastException: da

报错前提:

JAVA 中使用CXF配置WebService 在Webshpere上发布,报如下异常

Caused by: java.lang.ClassCastException: dao.code.model.TaskListDetail$JaxbAccessorM_getJkczrq_setJkczrq_java_lang_Long incompatible with com.sun.xml.bind.v2.runtime.reflect.Accessor

Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:323)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:234)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:466)

Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:411)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:467)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:615)

Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.reflect.InvocationTargetException]
at org.apache.cxf.jaxb.JAXBUtils.createRIContext(JAXBUtils.java:562)
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:408)
... 141 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.apache.cxf.jaxb.JAXBUtils.createRIContext(JAXBUtils.java:560)
... 142 more
Caused by: java.lang.ClassCastException: dao.code.model.TaskListDetail$JaxbAccessorM_getJkczrq_setJkczrq_java_lang_Long incompatible with com.sun.xml.bind.v2.runtime.reflect.Accessor
at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.instanciate(OptimizedAccessorFactory.java:190)

主要看一下红色部分,原因是在JAVA项目中使用CXF配置WebServcie服务端,接口中使用到对象类型时,没在其MODEL文件中加如下内容:

@XmlRootElement(name="User")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"xtczdm","xtczid","xtczkl","xtczry","jkzxsl","phone","xtjsry","xtrymc"})

XmlType 这个里的值,一定要是MODEL类中的所有字段。

源码:

package dao.code.model;
import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
* The persistent class for the JK_XTM01 database table.
*
* @author BEA Workshop
*/
@XmlRootElement(name="User")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"xtczdm","xtczid","xtczkl","xtczry","jkzxsl","phone","xtjsry","xtrymc"})
public class User extends dao.BaseModel implements Serializable{
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
private String xtczdm;
private Long xtczid;
private String xtczkl;
private String xtczry;
    private String jkzxsl;
    private String phone;
    private String xtjsry;
    private String xtrymc;
    public User() {
    }

public String getXtczdm() {
  return this.xtczdm;
}
public void setXtczdm(String xtczdm) {
  this.xtczdm = xtczdm;
}

public Long getXtczid() {
  return this.xtczid;
}
public void setXtczid(Long xtczid) {
  this.xtczid = xtczid;
}

public String getXtczkl() {
  return this.xtczkl;
}
public void setXtczkl(String xtczkl) {
  this.xtczkl = xtczkl;
}

public String getXtczry() {
  return this.xtczry;
}
public void setXtczry(String xtczry) {
  this.xtczry = xtczry;
}

public String getJkzxsl() {
  return jkzxsl;
}

public void setJkzxsl(String jkzxsl) {
  this.jkzxsl = jkzxsl;
}

public String getPhone() {
  return phone;
}

public void setPhone(String phone) {
  this.phone = phone;
}

public String getXtjsry() {
  return xtjsry;
}

public void setXtjsry(String xtjsry) {
  this.xtjsry = xtjsry;
}

public String getXtrymc() {
  return xtrymc;
}

public void setXtrymc(String xtrymc) {
  this.xtrymc = xtrymc;
}

public boolean equals(Object other) {
  if (this == other) {
   return true;
  }
  if (!(other instanceof User)) {
   return false;
  }
  User castOther = (User)other;
  return new EqualsBuilder()
   .isEquals();
    }
public int hashCode() {
  return new HashCodeBuilder()
   .toHashCode();
    }

public String toString() {
  return new ToStringBuilder(this)
   .toString();
}
}

你可能感兴趣的:(Webshpere上发布 JAVA 中使用CXF配置WebService Caused by: java.lang.ClassCastException: da)