我试图在REST中传递一个参数,但它会抛出异常:
Mar 15, 2015 3:09:00 AM com.sun.jersey.spi.container.ContainerRequest getEntity SEVERE: A message body reader for Java class com.backend.service.impl.resource.DummyParam, and Java type class com.backend.service.impl.resource.DummyParam, and MIME media type application/x-www-form-urlencoded was not found. The registered message body readers compatible with the MIME media type are: application/x-www-form-urlencoded -> com.sun.jersey.core.impl.provider.entity.FormProvider com.sun.jersey.core.impl.provider.entity.FormMultivaluedMapProvider
代码段如下:
@Path("/test/dummy")
public class DummyService {
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
@Produces({MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON})
@Path("/doStuff1")
public Response doStuff1(DummyParam param) {
System.out.println("Hiiiiiiiiii : "+param.getUsername());
return Response.ok().build();
}
}
@XmlRootElement(name = "dummyparam")
public class DummyParam {
private String username;
private String password;
@XmlElement(name = "user")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@XmlElement(name = "pwd")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
有人可以帮助我解决这个问题的原因吗?