2015-10-14 58 views
0

我试图整合springfox不回我现有的冲刺web应用程序我配置了springfox Web应用程序正确启动,但没有得到产生springfox这个API文档

这里的API文档是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有人可以帮助我在此

回答

0

它可能是一个迟到answer..but应该帮助人们仍在寻找/搜索

无论如何,下面的答案应该工作。 对HTML的ui.html处理程序需要 和他人webjars/**需要

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

,如果你有过滤器链来访问特定的网址,一定要忽略任何过滤cheking类似于上面的代码

@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文件的文件夹。 如果你已经有一个资源处理程序..不要忘了在那里包括这些。在这种情况下,不需要写一个特殊的资源处理程序