gpt4 book ai didi

java - Swagger 在 Eclipse 微配置文件应用程序上

转载 作者:行者123 更新时间:2023-12-02 02:07:04 25 4
gpt4 key购买 nike

我有一个 java microprofile 应用程序,我想向其中添加 swagger。该应用程序有一个“自定义”应用程序类

@ApplicationPath("/api")
public class RestApplication extends Application {

public RestApplication() {
Swagger swagger = new Swagger();
new SwaggerContextService().updateSwagger(swagger);

BeanConfig beanConfig = new BeanConfig();
beanConfig.setDescription("Parser for sheet music");
beanConfig.setTitle("Ironfox");
beanConfig.setVersion("0.0.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("se.pro12.ironfox");
beanConfig.setScan(true);
}
}

问题是 beanConfig.setScan(true) 失败并出现错误

java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;

我真的不明白为什么。我什至尝试向 google-collections 添加依赖项。

有人以前见过这个问题或者有解决办法吗?

我拥有的pom文件

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>se.pro12</groupId>
<artifactId>ironfox</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<runInBackground>false</runInBackground>
</properties>

<build>
<finalName>ironfox</finalName>

<plugins>
<plugin>
<groupId>fish.payara.maven.plugins</groupId>
<artifactId>payara-micro-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
<goal>start</goal>
</goals>
</execution>
</executions>
<configuration>
<payaraVersion>4.1.2.173</payaraVersion>
<useUberJar>true</useUberJar>
<deployWar>false</deployWar>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile-bom</artifactId>
<version>1.1.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.18.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.19</version>
</dependency>
</dependencies>
</project>

最佳答案

您使用的 Payara Micro 版本 (4.1.2.173) 使用旧版本的 Guava 库 - v19,它不提供 Swagger 所需的方法。

您有多种选择:

  • 按照描述禁用类加载委托(delegate) in the docs - 您可以在应用程序的 glassfish-web.xml 中本地完成
  • 将较新版本的 guava 库复制到 Payara Micro JAR 中,覆盖 MICRO-INF/runtime 中现有的 guava.jar
  • 等待几天,直到 Payara Micro 5.182 发布并使用 MicroProfile Open API 而不是 Swagger

升级到 Payara Micro 的新版本并没有帮助,因为它仍然使用相同版本的 Guava 库。

关于java - Swagger 在 Eclipse 微配置文件应用程序上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50620748/

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