Swagger-ui不显示任何api详细信息

时间:2016-10-07 16:18:41

标签: java spring-mvc swagger swagger-ui

我已成功将swagger整合到我的项目中

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>

我现在可以点击网址http://localhost:8080/myApp/v2/api-docs 并看到json返回描述我的REST api。 e.g。

{ ? 
   "swagger":"2.0",
   "info":{ ? 
      "description":"Api Documentation",
      "version":"1.0",
      "title":"Api Documentation",
      "termsOfService":"urn:tos",
      "contact":{ ? 

      },
      "license":{ ? 
         "name":"Apache 2.0",
         "url":"http://www.apache.org/licenses/LICENSE-2.0"
      }
   },
   "host":"localhost:8080",
   "basePath":"/myApp",
   "tags":[ ? 
      { ? 
         "name":"staff-controller",
         "description":"Staff Controller"
      },
      { ? 
         "name":"data-controller",
         "description":"Data Controller"
      },
      { ? 
         "name":"master-controller",
         "description":"Master Controller"
      },
      { ? 
         "name":"user-manager-controller",
         "description":"User Manager Controller"
      },
      { ? 
         "name":"client-controller",
         "description":"Client Controller"
      },
      { ? 
         "name":"request-controller",
         "description":"Request Controller"
      }
   ],

然后我接受了swagger-ui依赖

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

我创建了一个SwaggerConfig bean

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
            .build();
    }
}

和WebMVCConfig

@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}

然而,当我导航到http://localhost:8080/myApp/swagger-ui.html时,我看到了招摇标题,但没有填充任何信息。 Screenshot

还有什么我需要配置的吗? Swagger-ui是否需要通往项目根目录的路径?

我的web.xml确实配置了安全性(虽然我尝试将其关闭但没有影响)

<servlet>
    <servlet-name>myApp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                classpath:spring/application.xml
            </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>myApp</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

1 个答案:

答案 0 :(得分:0)

根据您的配置,swagger-ui.html的正确网址为http://localhost:8080/swagger-ui.html