在Tomcat中运行的Square Java SDK找不到jersey公共类



我正在开发使用Square java SDK的angular spring boot web应用程序。

当我试图通过Square Java SDK访问Square rest api时,我得到了以下异常。

我正在Tomcat 9版本中运行我的应用程序。

我检查了.war文件,它有jersey-commonjar、Injections类和createInjectionManager方法。

java.lang.NoSuchMethodError: org.glassfish.jersey.internal.inject.Injections.createInjectionManager([Lorg/glassfish/jersey/internal/inject/Binder;)Lorg/glassfish/jersey/internal/inject/InjectionManager;
at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:386) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341) ~[jersey-common-2.26.jar:na]
at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:723) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:286) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:141) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:111) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:107) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:98) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:443) ~[jersey-client-2.26-b03.jar:na]
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:349) ~[jersey-client-2.26-b03.jar:na]
at com.squareup.connect.ApiClient.invokeAPI(ApiClient.java:676) ~[connect-2.20191023.0.jar:na]
at com.squareup.connect.api.CatalogApi.batchRetrieveCatalogObjects(CatalogApi.java:178) ~[connect-2.20191023.0.jar:na]
import com.squareup.connect.ApiException;
import com.squareup.connect.Configuration;
import com.squareup.connect.api.CatalogApi;
import com.squareup.connect.auth.OAuth;
import com.squareup.connect.models.BatchRetrieveCatalogObjectsRequest;
import com.squareup.connect.models.BatchRetrieveCatalogObjectsResponse;
public class CatalogServiceImpl implements CatalogService {
@Override
public BatchRetrieveCatalogObjectsResponse getCatalogItems() {
ApiClient defaultClient = Configuration.getDefaultApiClient();
BatchRetrieveCatalogObjectsResponse result = null;
// Configure OAuth2 access token for authorization: oauth2
OAuth oauth2 = (OAuth) defaultClient.getAuthentication("oauth2");
oauth2.setAccessToken("");
CatalogApi apiInstance = new CatalogApi();
BatchRetrieveCatalogObjectsRequest body = new BatchRetrieveCatalogObjectsRequest();
// BatchRetrieveCatalogObjectsRequest | An object containing the fields to POST for the request.  See the corresponding object definition for field details.
try {
result = apiInstance.batchRetrieveCatalogObjects(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling CatalogApi#batchRetrieveCatalogObjects");
e.printStackTrace();
}
return result;
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.M3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-aws</artifactId>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-aws-jdbc</artifactId>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-aws-messaging</artifactId>-->
<!--        </dependency>-->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>connect</artifactId>
<version>2.20191023.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.29.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava -->
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.26-b03</version>
</dependency>
<!--        &lt;!&ndash; https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.glassfish.jersey.core</groupId>-->
<!--            <artifactId>jersey-common</artifactId>-->
<!--            <version>2.29</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.glassfish.jersey.inject</groupId>-->
<!--            <artifactId>jersey-hk2</artifactId>-->
<!--            <version>2.26</version>-->
<!--        </dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.26-b03</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

终于解决了这个问题。这是因为球衣罐子版本的不兼容性。这些是我设置的正确版本。

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava -->
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.26-b01</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.26</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

由于类路径上同时存在相同的jar文件,因此可能会发生错误。

所以打开你的文件夹,找到同一个罐子并删除它

我英语不好。。sry:(

相关内容

最新更新