使用SpringFox将Swagger集成到NON SpringBoot项目中

问题描述 投票:0回答:1

我和here有同样的问题。我想将swagger整合到一个非弹簧启动项目中。我按照回答here中给出的步骤使用springfox,但我在服务器启动时收到以下错误:

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的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;

所以然后我切换到了Spring的2.6.1版本,第二个错误就消失了,我得到了一个干净的服务器启动。

spring swagger springfox
1个回答
0
投票

我认为问题来自另一个丢失的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>
© www.soinside.com 2019 - 2024. All rights reserved.