找不到 / GET / swagger 的映射
No mapping found for / GET / swagger
我正在尝试为项目配置 swagger,但我收到无数次错误:
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
................
我有一个多项目图层。结构是:
项目名称
-- 项目1
--setting.gradle
--build.gradle
-- 项目2
--setting.gradle
--build.gradle
--setting.gradle
在每个 build.gradle 中我有这个依赖项:
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
SwaggerConfiguration class 是:
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/");
}
}
我还有一个 WebConfigure class:
@Configuration
@EnableWebMvc
@Slf4j
public class WebConfigure extends WebMvcConfigurationSupport {
@Bean
public AuthorizationInterceptor requestInterceptor() {
return new AuthorizationInterceptor();
}
@Override
protected void addInterceptors(InterceptorRegistry registry) {
log.info("Adding interceptor [{}]", AuthorizationInterceptor.class.getName());
registry.addInterceptor(requestInterceptor());
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
如果我尝试访问 http://localhost:8090/project1/api/swagger-ui.html 我收到此错误:
Swagger error
从 server.servlet.context 路径中删除“/api”。
不知何故招摇与那部分冲突。
我正在尝试为项目配置 swagger,但我收到无数次错误:
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
o.s.web.servlet.PageNotFound : No mapping for GET /project1/api/null/swagger-resources/configuration/ui"
................
我有一个多项目图层。结构是:
项目名称
-- 项目1
--setting.gradle
--build.gradle
-- 项目2
--setting.gradle
--build.gradle
--setting.gradle
在每个 build.gradle 中我有这个依赖项:
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
SwaggerConfiguration class 是:
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/");
}
}
我还有一个 WebConfigure class:
@Configuration
@EnableWebMvc
@Slf4j
public class WebConfigure extends WebMvcConfigurationSupport {
@Bean
public AuthorizationInterceptor requestInterceptor() {
return new AuthorizationInterceptor();
}
@Override
protected void addInterceptors(InterceptorRegistry registry) {
log.info("Adding interceptor [{}]", AuthorizationInterceptor.class.getName());
registry.addInterceptor(requestInterceptor());
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
如果我尝试访问 http://localhost:8090/project1/api/swagger-ui.html 我收到此错误:
Swagger error
从 server.servlet.context 路径中删除“/api”。
不知何故招摇与那部分冲突。