gpt4 book ai didi

java - 在 Tomcat 中运行的 Square Java SDK 无法找到 Jersey 通用类

转载 作者:行者123 更新时间:2023-12-02 09:18:00 31 4
gpt4 key购买 nike

我正在开发使用 Square java SDK 的 Angular Spring Boot Web 应用程序。

当我尝试通过 Square Java SDK 访问 Square Rest api 时,出现以下异常。

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

我检查了 .war 文件,它有 jersey-common jar 和 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>

最佳答案

终于解决了。这是因为 jersey jar 版本不兼容。这些是适合我的设置的正确版本。

    <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>

关于java - 在 Tomcat 中运行的 Square Java SDK 无法找到 Jersey 通用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58869167/

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