0
我正在使用swagger 2和spring mvc。Swagger 2&spring MVC - 忽略战争环境路径
战争文件是网络app.war和扬鞭基础URL显示为/web-app/rest/api
我想删除战争上下文路径,因此,API调用可以被制成
example.com/rest/api
和不example.com/web-app/rest/api
SwaggerConfig.java
@Configuration
@EnableWebMvc
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket api() {
// @formatter:off
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.any())
.build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Rest API")
.description("Describes the restful interface")
.build();
}
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
不知道什么ü在IDE改变它意味着什么?这个问题只有在swagger发出请求时(试用它!),它会将/ web-app添加到URL中。 如果我直接访问URL是浏览器没有/ web-app一切正常。 – Coder