0

I have a java microprofile application that I want to add swagger to. The application has a "custom" Application class

@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);
    }
}

The problem is that it is failing on beanConfig.setScan(true) with the error

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

And I don't really understand why. I've even tries adding a dependency to google-collections.

Has anyone seen this before or have any ideas of how to solve it?

the pom file that I have

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

1 回答 1

2

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

你有几个选择:

  • 文档中所述禁用类加载委托- 您可以在应用程序的 glassfish-web.xml 中本地执行此操作
  • 将较新版本的 guava 库复制到 Payara Micro JAR 中,覆盖现有的 guava.jarMICRO-INF/runtime
  • 等待几天,直到 Payara Micro 5.182 发布并使用 MicroProfile Open API 而不是 Swagger

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

于 2018-06-07T13:35:06.993 回答