我有一个rest ful web服务,它将通过hibernate从数据库中获取某些值 并将使用seeter和getter设置这些值。我能够查看值,但在尝试使用Web服务时,我得到了异常 “未找到Java类和Java类型类以及MIME媒体类型application / 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方法设置值。