Answer the question
In order to leave comments, you need to log in
Why do I get null URL errors when accessing swagger on tomcat? How to fix it?
Hello. We develop web
rest api
on java
. We use spring
it sping boot
for auto-configuration and local launch of applications. We also use swagger
it to work with our REST APIs. Deploy it in Apache Tomcat 9.0.x
.
Library versions (from pom.xml
):
<properties>
<springframework.boot>2.1.2.RELEASE</springframework.boot>
<springframework.version>5.1.4.RELEASE</springframework.version>
<swagger.version>2.9.2</swagger.version>
<java.version>11</java.version>
<tomcat.version>9.0.14</tomcat.version>
<postgresql.jdbc.version>42.2.5</postgresql.jdbc.version>
</properties>
[ERROR] 2019-08-01 10:07:48.791 [http-nio-8080-exec-7] RestExceptionHandler - No handler found for GET /my-project-rest/api/v1/null/swagger-resources/configuration/security
org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /my-project/api/v1/null/swagger-resources/configuration/security
at org.springframework.web.servlet.DispatcherServlet.noHandlerFound(DispatcherServlet.java:1252) [spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]
бин
in the main configuration):@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
//every controller without @DateTimeFormat
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateConverter(DATE_FORMAT_RU));
registry.addConverter(new LocalDateTimeConverter(DATE_TIME_FORMAT_RU));
}
//Enable mappingJackson2HttpMessageConverter
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(stringConverter());
converters.add(mappingJackson2HttpMessageConverter());
}
//Enable matrix variable
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper pathHelper = new UrlPathHelper();
pathHelper.setRemoveSemicolonContent(false);
configurer.setUrlPathHelper(pathHelper);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/null/swagger-resources/**") // !!!!!
.addResourceLocations("classpath:/META-INF/resources/");
/*
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
*/
}
};
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question