使用 SpringFox 将 Swagger 集成到非 SpringBoot 项目中
Swagger integration into a NON SpringBoot project using SpringFox
我有与使用 springfox 的 here. I want to integrate swagger into a non spring boot project. I followed the steps given in the answer 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>
更新:
所以我认为我缺少 jackson fasterxml 依赖项。我用 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;
然后我切换到 2.6.1 版本的 springfox,第二个错误消失了,我得到了一个干净的服务器启动。
我认为问题来自另一个丢失的 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>
添加
<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
错误
我有与使用 springfox 的 here. I want to integrate swagger into a non spring boot project. I followed the steps given in the answer 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>
更新: 所以我认为我缺少 jackson fasterxml 依赖项。我用 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;
然后我切换到 2.6.1 版本的 springfox,第二个错误消失了,我得到了一个干净的服务器启动。
我认为问题来自另一个丢失的 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>
添加
<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
错误