在 spring boot应用程序中,我遇到以下异常
错误:找不到带有URI的HTTP请求的映射 [/exp/swagger-ui.html]在DispatcherServlet中,名称为 'dispatcherServlet'
URL:localhost:8080 / exp / swagger-ui.html
这是我的配置文件:
Swagger配置
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.remedy.exp.controllers")).paths(PathSelectors.any())
.build();
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/exp/v2/api-docs", "/v2/api-docs");
registry.addRedirectViewController("/exp/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
registry.addRedirectViewController("/exp/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
registry.addRedirectViewController("/exp/swagger-resources", "/swagger-resources");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/exp/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry.addResourceHandler("/exp/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
CORS和Json序列化的配置:
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods( HttpMethod.GET.name() , HttpMethod.POST.name(), HttpMethod.PUT.name(), HttpMethod.DELETE.name(), HttpMethod.OPTIONS.name())
.allowedOrigins("*")
.allowedHeaders("*");
}
public MappingJackson2HttpMessageConverter jacksonMessageConverter() {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Hibernate5Module());
messageConverter.setObjectMapper(mapper);
return messageConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(jacksonMessageConverter());
addDefaultHttpMessageConverters(converters);
super.configureMessageConverters(converters);
}
}
任何帮助将不胜感激!
谢谢!