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

时间:2019-03-03 06:30:15

标签: spring swagger springfox

我和here有相同的问题。我想将swagger集成到非春季启动项目中。我遵循了使用Springfox的答案here中给出的步骤,但是在服务器启动时出现以下错误:

public  AccessToken getToken() {
        // Required for all types of tokens
        String twilioAccountSid ="AC601f2c7***7ed***640***264c***d0d";
        String twilioApiKey = "SK684***dda***c81****6c4a****093**";
        String twilioApiSecret ="96****dbc06****b74d50***b9***3*4";
        String serviceSid="IS***a29****e24****5d****4b20**3e*";

        String identity = "joshua.hamilton@gmail.com";

        ChatGrant grant = new ChatGrant();
        grant.setServiceSid(serviceSid);

        AccessToken token = new AccessToken.Builder(twilioAccountSid, 
       twilioApiKey, twilioApiSecret)
                .identity(identity).grant(grant).build();

        Log.e("++==--",""+token.toJwt());

        //.identity(identity).grant(grant);

     return token;
    }

这些是添加的依赖项:

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

更新: 所以我想我缺少杰克逊的快速XML依赖。我用pom.xml随机播放,错误消失了。仍然尝试将造成问题的确切依赖性归零。

但是这个错误消失了,但又弹出了一个

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

因此,然后我切换到了2.6.1版本的springfox,第二个错误消失了,并且我顺利地启动了服务器。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

添加

<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错误