spring-mvc - springfox-swagger-3-0- 不适用于非启动 spring4 mvc 项目
问题描述
参考:突然 Springfox Swagger 3.0 无法与 spring webflux 一起使用
2.9.2 版运行良好。但是当我将它升级到 3.0.0 时它失败了。
我遇到了同样的问题,但区别只是......我没有使用弹簧靴。
我有 spring mvc4 项目并添加了 3.0.0 版本的 swagger2 ......但我无法查看 swagger-ui。
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
SwaggerConfig.java
@Configuration
@ComponentScan
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*")).build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("TITLE").description("INFO").version("V1.0")
.termsOfServiceUrl("http://terms-of-services.url").license("LICENSE")
.licenseUrl("http://url-to-license.com").build();
}
@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/");
}
}
并尝试如下所示一路狂妄自大。
localhost:8080/swagger-ui/index.html
localhost:8080/swagger-ui.html
localhost:8080/swagger-ui/
所有这些都不起作用.. :(
解决方案
推荐阅读
- twilio - Twilio - 带有 DTMF 音调的媒体流
- ietf-netmod-yang - 仅允许 YANG 模型中单独列表中的唯一键
- java - 如果找到匹配项,如何从列表中提取项目并添加到新列表中?
- sql - 优化查询,检查 user_id 是否存在于许多表中
- javascript - 如何在每个步骤中组合带有条件检查的 JS 函数?
- python - 有非接触式温度计的协议文件吗?
- swift - (WatchConnectivity) WCSession 缺少委托
- javascript - 设置数据时按钮 onclick 打开窗口
- excel - 通过更改范围内的值,刷新总和值在 Excel 中通过 VBA 宏获取
- reactjs - 组件异常无效类型