gpt4 book ai didi

java - jackson.databind 没有这样的方法错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:06:43 30 4
gpt4 key购买 nike

我正在使用 auth0-javaauth0 交互的客户端库v2服务,我的代码编译并在我的开发环境中运行良好,但是当我在另一个测试环境中部署该构建时,它会抛出以下异常:

java.lang.NoSuchMethodError:com.fasterxml.jackson.databind.ObjectMapper.readerFor(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectReader;
at com.auth0.json.mgmt.users.UsersPageDeserializer.getArrayElements(UsersPageDeserializer.java:52)
at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:30)
at com.auth0.json.mgmt.users.UsersPageDeserializer.deserialize(UsersPageDeserializer.java:15)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3562)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2597)
at com.auth0.net.CustomRequest.parseResponse(CustomRequest.java:63)
at com.auth0.net.BaseRequest.execute(BaseRequest.java:37)
at com.myapp.security.Auth0Service.getUserByEmail(Auth0Service.java:246)
at com.myapp.security.Auth0Service.checkForExsistingAuth0Account(Auth0Service.java:266)
at com.myapp.security.AdminUILayout.lambda$launchProgressUpdater$0(AdminUILayout.java:293)
at java.lang.Thread.run(Thread.java:745)

我已经解决了几个 stackover 流程​​问题,例如 this并通过清洁尝试.m2/repository/com/fasterxml该测试环境的文件夹,但无法解决没有此类方法的错误这是我的pom文件,相关代码如下:

代码

public User getUserByEmail(String email){
UserFilter filter = new UserFilter();
filter.withQuery(email);
Request<UsersPage> request = mgmt.users().list(filter);
try {
UsersPage response = request.execute();
for (User u:response.getItems()) {
if (u.getEmail().equals(email)) {
return u;
}
}
} catch (APIException exception) {
// api error
System.out.println("APIException:::::"+exception.getDescription());
} catch (Auth0Exception exception) {
// request error
System.out.println("Auth0Exception:::::"+exception.getMessage());
}catch(Exception ex){
System.out.println("Other exception:::::"+ex.getMessage());
}
return null;
}

pom.xml

<properties>
<jackson.version>2.8.5</jackson.version>
</properties>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0</artifactId>
<version>1.0.0</version>
</dependency>

更新我已将那些 jackson 依赖项移动到 <dependencyManagement> 中我的部分 pom.xml文件,

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</dependencyManagement>

根据 maven documentation ,无论哪个版本的库jackson-core由依赖项请求,版本 ${jackson.version}将始终被使用,我的代码仍然在本地工作,但在那个测试服务器上 异常保持不变,即使我在该测试服务器代码中部署我的 war 文件也会抛出相同的异常。

最佳答案

很可能你已经针对不同版本的类编译了你的代码,而不是你在运行它时使用的版本。

请确保在您运行代码的环境中没有任何其他版本的 jackson-databind 依赖于您的类路径。

关于java - jackson.databind 没有这样的方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43784122/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com