我正在尝试将springfox集成到我现有的sprint web应用程序中,我配置了springfox,web应用程序正在正确启动,但没有生成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。有人能帮帮我吗?
发布于 2016-07-14 23:01:45
这可能是一个很晚的answer..but应该可以帮助人们仍然在寻找/搜索
无论如何,下面的答案应该是有效的。对于html,需要ui.html处理程序;对于其他处理程序,则需要webjars/**
uri.startsWith("/swagger")|| uri.startsWith("/webjars")||uri.startsWith("/v2/api-docs");如果使用过滤器链来访问特定url,请确保忽略与上述代码类似的任何过滤器检查
@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文件。如果您已经有一个资源handler..donot,请忘记包含这些there.In,在这种情况下,不需要编写特殊的资源处理程序
https://stackoverflow.com/questions/33119888
复制相似问题