2

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

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实体映射,但我不确定。

4

3 回答 3

6

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

于 2013-08-27T15:36:09.183 回答
3

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

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

于 2014-08-22T12:19:11.123 回答
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>
于 2013-10-24T10:28:46.540 回答