Rest Webservice中的AbstractMethodError

时间:2013-08-27 12:44:48

标签: java json rest exception

我是网络服务的新手。我尝试将jax.ws..网络服务与jerseyspring一起使用。当我尝试在Windows中使用Chrome Post ClientCURL发送请求时,会发生以下堆栈跟踪。

SEVERE: Servlet.service() for servlet [jersey-serlvet] in context with path [/rest] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findDeserializer(AnnotationIntrospector.java:1335)
at org.codehaus.jackson.map.deser.BasicDeserializerFactory.findDeserializerFromAnnotation(BasicDeserializerFactory.java:675)
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:535)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:432)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCache2(StdDeserializerProvider.java:341)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:321)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.findValueDeserializer(StdDeserializerProvider.java:167)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.findTypedValueDeserializer(StdDeserializerProvider.java:188)
at org.codehaus.jackson.map.ObjectMapper._findRootDeserializer(ObjectMapper.java:2820)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2690)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
..............................

以下是我的示例代码:

@Path("/loginPoint")
@Service
public class UserService {

@Resource(name= "commanUserService")
private CommanUserService commanUserService;

@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response login(LoginRequest request){
    System.out.println("Hello In web Services >>>>>>>>>>>>>>>>>>>>>>>>> ");
    LoginResponse  response = commanUserService.getUserloginInformation(request);
    return Response.status(Status.OK).entity(response).build();
 }
}

LoginRequest.java文件代码:

@XmlRootElement(name="loginRequest")
public class LoginRequest {
private String userName;
private String password;

@XmlElement("userName")
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}

@XmlElement("password")
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
 }
}

我认为问题在于将JSON请求参数映射到LoginRequest实体,但我不确定。

3 个答案:

答案 0 :(得分:5)

问题是杰克逊版本之间不匹配。

答案 1 :(得分:3)

当使用jackson-core-asl依赖与jackson-mapper-asl时,选择相同的版本。

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
    </dependency>

答案 2 :(得分:2)

我遇到了同样的问题并解决了自己。问题在于 jersy jersy-json,jersy-server )和 jackson 之间的版本兼容性( jackson-core-asl ,jackson-mapper-asl )罐子。

所以请使用兼容版本,如jersy 1.8和jackson 1.8.1罐子。