无法实例化提供程序io.swagger.scala.converter.SwaggerScalaModelConverter

无法实例化提供程序io.swagger.scala.converter.SwaggerScalaModelConverter,scala,swagger,jersey-2.0,Scala,Swagger,Jersey 2.0,当我试图将招摇过市纳入我的API时,我遇到了一些问题 我的API使用Jersey 2.22,语言是Scala。我已将以下依赖项添加到pom中: <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.12</version> </depen

当我试图将招摇过市纳入我的API时,我遇到了一些问题

我的API使用Jersey 2.22,语言是Scala。我已将以下依赖项添加到pom中:

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.5.12</version>
</dependency>

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-scala-module_2.11</artifactId>
    <version>1.0.3</version>
</dependency> 
结果:

"definitions" : {
    "some model" : {
      "type" : "object"
    }
  }

有人有线索吗?

嗯,经过一番繁重的调试,我找到了。看起来我使用的swagger maven插件(3.1.1)使用的是swagger core 1.5.4。这个招摇过市的核心依赖项依赖于Jackson 2.4.5

swagger-scala-module_2.11使用的是Jackson 2.8.7。“无法从最终类继承”错误来自TypeReference类,该类显然在2.8.7中更改/引入

该解决方案通过使用dependencies块将swagger-scala-module_2.11包含在swagger maven插件中:

<build>
    <plugins>
        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>${swagger-scala-maven-plugin}</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-scala-module_2.11</artifactId>
                    <version>1.0.3</version>
                </dependency>
            </dependencies>
            <configuration>
                <apiSources>
                    <apiSource>
                        <locations>
                            <location>${swagger.locations}</location>
                        </locations>
                        <springmvc>false</springmvc>
                        <host>${swagger.host}</host>
                        <basePath>${base.path}</basePath>
                        <info>
                            <title>${swagger.title}</title>
                            <version>${project.version}</version>
                            <description>${swagger.description}</description>
                        </info>
                        <swaggerDirectory>${project.build.directory}/</swaggerDirectory>
                        <outputFormats>json</outputFormats>
                    </apiSource>
                </apiSources>
            </configuration>
        </plugin>
    </plugins>
</build>

com.github.kongchen
大摇大摆的maven插件
${swagger scala maven插件}
编译
生成
昂首阔步
swagger-scala-module_2.11
1.0.3
${swagger.locations}
假的
${swagger.host}
${base.path}
${swagger.title}
${project.version}
${swagger.description}
${project.build.directory}/
json

这将使swagger maven插件使用swagger core 1.5.12而不是提供的1.5.9

经过一番繁重的调试,我终于找到了答案。看起来我使用的swagger maven插件(3.1.1)使用的是swagger core 1.5.4。这个招摇过市的核心依赖项依赖于Jackson 2.4.5

swagger-scala-module_2.11使用的是Jackson 2.8.7。“无法从最终类继承”错误来自TypeReference类,该类显然在2.8.7中更改/引入

该解决方案通过使用dependencies块将swagger-scala-module_2.11包含在swagger maven插件中:

<build>
    <plugins>
        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>${swagger-scala-maven-plugin}</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-scala-module_2.11</artifactId>
                    <version>1.0.3</version>
                </dependency>
            </dependencies>
            <configuration>
                <apiSources>
                    <apiSource>
                        <locations>
                            <location>${swagger.locations}</location>
                        </locations>
                        <springmvc>false</springmvc>
                        <host>${swagger.host}</host>
                        <basePath>${base.path}</basePath>
                        <info>
                            <title>${swagger.title}</title>
                            <version>${project.version}</version>
                            <description>${swagger.description}</description>
                        </info>
                        <swaggerDirectory>${project.build.directory}/</swaggerDirectory>
                        <outputFormats>json</outputFormats>
                    </apiSource>
                </apiSources>
            </configuration>
        </plugin>
    </plugins>
</build>

com.github.kongchen
大摇大摆的maven插件
${swagger scala maven插件}
编译
生成
昂首阔步
swagger-scala-module_2.11
1.0.3
${swagger.locations}
假的
${swagger.host}
${base.path}
${swagger.title}
${project.version}
${swagger.description}
${project.build.directory}/
json

这将使swagger maven插件使用swagger core 1.5.12而不是提供的1.5.9

我在Play Framework 2.4.6项目中使用SBT时遇到了同样的问题。GieJay提供的答案在我的案例中也被证明是正确的,我只是想指出我在SBT环境中的解决方案;在我的
库依赖项中

“io.swagger”%%“swagger-play2”%%“1.5.1”

这在另一个使用Play2.4.8的项目中运行良好,但我在一个较旧的Play版本中遇到了这个问题。 我所要做的就是添加

“io.swagger”%”swagger-scala-module_2.11“%”1.0.3“


在Play Framework 2.4.6项目中使用SBT时,我遇到了同样的问题。GieJay提供的答案在我的案例中也被证明是正确的,我只是想指出我在SBT环境中的解决方案;在我的
库依赖项中

“io.swagger”%%“swagger-play2”%%“1.5.1”

这在另一个使用Play2.4.8的项目中运行良好,但我在一个较旧的Play版本中遇到了这个问题。 我所要做的就是添加

“io.swagger”%”swagger-scala-module_2.11“%”1.0.3“

所有的工作都像一个符咒

"definitions" : {
    "some model" : {
      "type" : "object"
    }
  }
<build>
    <plugins>
        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>${swagger-scala-maven-plugin}</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-scala-module_2.11</artifactId>
                    <version>1.0.3</version>
                </dependency>
            </dependencies>
            <configuration>
                <apiSources>
                    <apiSource>
                        <locations>
                            <location>${swagger.locations}</location>
                        </locations>
                        <springmvc>false</springmvc>
                        <host>${swagger.host}</host>
                        <basePath>${base.path}</basePath>
                        <info>
                            <title>${swagger.title}</title>
                            <version>${project.version}</version>
                            <description>${swagger.description}</description>
                        </info>
                        <swaggerDirectory>${project.build.directory}/</swaggerDirectory>
                        <outputFormats>json</outputFormats>
                    </apiSource>
                </apiSources>
            </configuration>
        </plugin>
    </plugins>
</build>