我有一个spring mvc
我正在迁移springfox
到springdoc swagger
我已按照此链接中提到的步骤进行操作,但是当我尝试访问 swagger 页面时,它给了我以下错误
未找到带有 URL“/swagger-ui/index.html”的 http 请求的映射
这是我的依赖项
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/");
}
}
这是我的拦截器
<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>
我不确定我在这里做错了什么,
任何帮助,将不胜感激。