我收到错误消息:java.lang.NoSuchFieldError: EXCLUDE_EMPTY
当我使用 docker-client 和 jersey-hk2 时,仅使用 docker-client 我就可以毫无问题地运行单元测试。我不得不添加球衣,因为我在服务器中运行应用程序时遇到了其他问题。这是 pom.xml 的样子:
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>docker-client</artifactId>
<version>8.16.0</version>
</dependency>
这是我的测试:
@Test
public void checkingTest() throws DockerException, InterruptedException {
try {
List<com.spotify.docker.client.messages.Image> sortedImages = getImages();
if (!sortedImages.isEmpty()) {
final String latestId = Collections.max(sortedImages,
Comparator.comparingLong(img -> Long.parseLong(img.created())))
.id();
System.out.println("ids:" + latestId);
sortedImages.stream()
.filter(img -> !img.id().equals(latestId))
.forEach(img -> {
System.out.println("idsToDelete:" + img.id());
});
}
}
catch (DockerCertificateException e) {
e.printStackTrace();
}
}
private List<com.spotify.docker.client.messages.Image> getImages()
throws DockerCertificateException, DockerException, InterruptedException
{
final DockerClient dockerClient =
DefaultDockerClient.fromEnv().connectTimeoutMillis(TimeUnit.SECONDS.toMillis(3)).build();
List<com.spotify.docker.client.messages.Image> resp = dockerClient.listImages()
.stream()
.filter(image -> image.labels() != null && image.labels().containsValue("dockerImage"))
.collect(
Collectors.toList());
return resp;
}
我收到下一个错误:
java.lang.NoSuchFieldError: EXCLUDE_EMPTY
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:150)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:468)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:477)
at com.spotify.docker.client.DefaultDockerClient.<init>(DefaultDockerClient.java:334)
没有jersey-hk2
我能够正确运行测试,但正如我之前所说,它是必需的。没有这种依赖关系,我进入了服务器站点:
java.lang.NullPointerException: null
at org.glassfish.hk2.utilities.ServiceLocatorUtilities.addClasses(ServiceLocatorUtilities.java:412)
at org.glassfish.hk2.utilities.ServiceLocatorUtilities.enablePerThreadScope(ServiceLocatorUtilities.java:84