我正在尝试为项目配置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"
................
我有一个多项目层。结构是:
项目名
-project1
--setting.gradle
--build.gradle
-project2
--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类为:
@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类:
@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,则会收到此错误:
从server.servlet.context-path中删除“ / api”。
招摇莫名地与那部分冲突。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句