0

I have a spring mvc I am migrating from springfox to springdoc swagger I have followed the steps mentioned in this link, but when I try to access the swagger page, it gives me below error

no mapping found for http request with url "/swagger-ui/index.html"

here is my dependencies

org.springdoc springdoc-openapi-ui 1.5.8

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

    <display-name>TestService</display-name>

    <context-param>
        <param-name>applicationName</param-name>
        <param-value>Test</param-value>
    </context-param>

    <listener>
        <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>

    <!-- Provide access to the ServletContext through ServletContextSingleton -->
    <listener>
        <listener-class>com.example.test.servlet.ApplicationListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>Test</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>
    

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/swagger-ui.html</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Test</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>RequestContextFilter</filter-name>
        <filter-class>com.example.test.rest.web.filter.RequestContextFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>RequestContextFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

WebConfig.java

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @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/");
    }
}

Here is my interceptors

<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/swagger**"/>
            <mvc:exclude-mapping path="/swagger-ui**"/>
            <mvc:exclude-mapping path="/swagger-ui/**"/>
            <mvc:exclude-mapping path="/swagger-resources/**"/>
            <mvc:exclude-mapping path="/v3/**"/>
            <mvc:exclude-mapping path="/v2/api-docs**"/>
            <mvc:exclude-mapping path="/v3/api-docs**"/>
            <mvc:exclude-mapping path="/configuration/security**"/>
            <mvc:exclude-mapping path="/configuration/ui**"/>
            <mvc:exclude-mapping path="/webjars/**"/>
            <beans:ref bean="localAuthorizationInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>

I am not sure what I am doing wrong here,

Any help would be appreciated.

Doctor Who
  • 747
  • 1
  • 5
  • 28
  • I think you have to use a different URL as mentioned in the documentation: "The Swagger UI page will then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs" Or which URL are you calling when your error pops up? – doct0re Nov 23 '21 at 12:34
  • even if I try to access any link it gives me that error – Doctor Who Nov 23 '21 at 12:36
  • @Grim no, migrating from `springfox 3.0.0` to `springdoc-openapi-ui` – Doctor Who Nov 26 '21 at 13:59
  • sorry it was typo. – Doctor Who Nov 29 '21 at 07:50

1 Answers1

0

Springdoc is directly incompatible to Swagger but both support open-api3. Since the minimum denominator is oa3 you should have a v3 in the url.

Try one of theese

http://localhost:8080/v3/swagger-ui/
http://localhost:8080/v3/swagger-ui.html
http://localhost:8080/v3/api-docs/swagger-config

Be warned, springdoc have "projections" that are incompatible to oa3/swagger. You better remain on springdoc if you like to use "projections", but this is a my oppinion only.

Grim
  • 1,938
  • 10
  • 56
  • 123