springfox没有返回api doc

时间:2015-10-14 08:04:49

标签: spring-mvc swagger-2.0 springfox

我试图将springfox集成到我现有的sprint web应用程序中我配置了springfox,web应用程序正在启动,但api doc没有生成

这是springfox配置类

@EnableSwagger2 //Loads the spring beans required by the framework
public class SwaggerConfig {

  @Bean
  public Docket swaggerSpringMvcPlugin() {

    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
  }
}

这是bean创建

 <bean id="config" class="com.myApp.general.SwaggerConfig"/>

以下是控制器

@Controller
public class MyController {

    @ApiOperation(value = "Gets architecture services",
        notes = "",
        produces = "application/json")
    @RequestMapping(value = "v1/users", method = RequestMethod.GET)
    @ResponseBody
    public Object users(HttpServletResponse response) {
         //method implementation
    }
}

当我尝试获取api文档时,它只返回404.有人可以帮助我吗

1 个答案:

答案 0 :(得分:0)

这可能是一个迟到的答案..但应该帮助人们仍然寻找/搜索

无论如何,以下答案应该有效。 对于html,需要ui.html处理程序 对于其他人来说,需要webjars / **

uri.startsWith("/swagger")|| uri.startsWith("/webjars")||uri.startsWith("/v2/api-docs");

如果您有特定于访问权限的网址的过滤器链,请务必省略与上述代码类似的任何过滤器链接

@Component
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

       registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

}....

添加上面的代码使你的spring应用程序可以查看swagger-ui文件的文件夹。 如果你已经有一个资源处理程序..忘记在那里包含这些。在这种情况下,不需要编写特殊的资源处理程序

相关问题