我有一个完整的网络服务,它将通过休眠从数据库中获取某些值,并使用 Seeter 和 getter 设置这些值。我能够设置这些值,但在尝试使用 Web 服务时出现异常“找不到 Java 类和 Java 类型类和 MIME 媒体类型应用程序/xml 的消息正文编写器”
我的网络服务代码是
@Path("/IFConfig")
public class IFconfigService {
private static final String FILE_PATH = "C:\\Users\\298637\\Desktop\\sample.xml";
@GET
@Path("/get/{varX}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public IfMainbo Webserviceoutput(@PathParam("varX") String varX)
{
List iFObjects = new ArrayList();
String iFName=varX;
System.out.println("the parameter name is "+iFName);
IfMainbo ifMainbo = new IfMainbo();
IfMain ifMain = new IfMain();
FetchConfiguration passing = new FetchConfiguration();
iFObjects = passing.loadConfigData(iFName);
System.out.println("OBJECT SIZE"+iFObjects.size());
for (Iterator iterator = iFObjects.iterator(); iterator.hasNext();){
ifMain = (IfMain)iterator.next();
}
ifMainbo.setIfId(ifMain.getIfId());
ifMainbo.setIfName(ifMain.getIfName());
System.out.println(ifMainbo.getIfId());
System.out.println(ifMainbo.getIfName());
return ifMainbo;
}
}
我的提供类或 setter 和 getter 类代码是
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ifMainbo", propOrder = {
"entities",
"ifId",
"ifName"
})
public class IfMainbo implements MessageBodyWriter{
@XmlElement(required = true, nillable = true)
protected List<Object> entities;
protected String ifId;
protected String ifName;
/**
* Gets the value of the entities property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the entities property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getEntities().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Object }
*
*
*/
public List<Object> getEntities() {
if (entities == null) {
entities = new ArrayList<Object>();
}
return this.entities;
}
/**
* Gets the value of the ifId property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getIfId() {
return ifId;
}
/**
* Sets the value of the ifId property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setIfId(String value) {
this.ifId = value;
}
/**
* Gets the value of the ifName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getIfName() {
return ifName;
}
/**
* Sets the value of the ifName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setIfName(String value) {
this.ifName = value;
}
@Override
public long getSize(Object arg0, Class arg1, Type arg2, Annotation[] arg3,
MediaType arg4) {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2,
MediaType arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public void writeTo(Object arg0, Class arg1, Type arg2, Annotation[] arg3,
MediaType arg4, MultivaluedMap arg5, OutputStream arg6)
throws IOException, WebApplicationException {
// TODO Auto-generated method stub
}
}
谁能告诉我为什么会这样,因为我可以使用 setter 方法设置值。