我有自己的RequestMappingHandlerMapping,并且正在使用springfox-swagger- ui。添加自定义映射后,我无法在http:// localhost:8080 / swagger- ui.html上实现swagger ui 。有任何想法吗?
这是我的配置。
@Configuration public class WebMvcConfig extends WebMvcConfigurationSupport { @Override @Bean public RequestMappingHandlerMapping requestMappingHandlerMapping() { return new ApiVersionRequestMappingHandlerMapping("v"); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry .addResourceHandler("/webjars/**") .addResourceLocations("(META-INF/resources/webjars"); } }
这是我的pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency>
我终于找到了!正确的配置是这样的:
@Configuration public class VersioningMappingHandlerConfig { @Bean public ApiVersionRequestMappingHandlerMapping customMappingHandlerMapping() { ApiVersionRequestMappingHandlerMapping handler = new ApiVersionRequestMappingHandlerMapping("v", 1, 1); handler.setOrder(-1); return handler; } }
注意:没有extends WebMvcConfigurationSupport,bean名称是customMappingHandlerMapping
extends WebMvcConfigurationSupport
customMappingHandlerMapping