【问题标题】:Swagger integration into a NON SpringBoot project using SpringFox使用 SpringFox 将 Swagger 集成到非 SpringBoot 项目中
【发布时间】:2019-07-24 18:12:31
【问题描述】:

我和here 有同样的问题。我想将 swagger 集成到 非 Spring Boot 项目中。我按照使用 springfox 的答案here 中给出的步骤操作,但在服务器启动时出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cachingModelPropertiesProvider' defined in URL [jar:file:*/WEB-INF/lib/springfox-schema-2.9.2.jar!/springfox/documentation/schema/property/CachingModelPropertiesProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'optimized': Failed to introspect bean class [springfox.documentation.schema.property.OptimizedModelPropertiesProvider] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/classmate/members/ResolvedParameterizedMember

这些是添加的依赖项:

             <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger-ui</artifactId>
                    <version>2.9.2</version>
            </dependency>
            <dependency>
                    <groupId>io.springfox</groupId>
                    <artifactId>springfox-swagger2</artifactId>
                    <version>2.9.2</version>
            </dependency>

更新: 所以我想我错过了杰克逊 fastxml 依赖项。我用 pom.xml 来回移动,错误就消失了。仍在尝试将导致问题的确切依赖归零。

虽然这个错误消失了,但又弹出了一个:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;

于是我切换到 springfox 的 2.6.1 版本,第二个错误消失了,我得到了一个很好的干净服务器启动。

【问题讨论】:

  • 你能发布你的 pom.xml 吗?
  • 我认为问题来自另一个丢失的 jar ,你能发布你的 pom.xml 吗?
  • 我已经更新了帖子。

标签: spring swagger springfox


【解决方案1】:

添加

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>20.0</version>
  <exclusions>
    <exclusion>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </exclusion>
  </exclusions>
</dependency>

解决了nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable 错误

【讨论】:

    【解决方案2】:

    我认为问题来自另一个缺少的 jar,请确保您有两个依赖项

    <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2017-09-29
      • 1970-01-01
      相关资源
      最近更新 更多