如何解决SpringBoot 3.4.4中的WhiteLabel Error Page 404问题
SpringDoc Swagger UI 404 错误排查与解决
针对你遇到的SpringDoc配置后仍出现404白页的问题,可按以下步骤排查解决:
检查访问路径是否正确
你使用的SpringDoc 2.8.6属于2.x版本,Swagger UI的默认访问路径是/swagger-ui/index.html(或简化为/swagger-ui/),而非旧版SpringFox常用的/swagger-ui.html,直接访问正确路径尝试。确认版本兼容性
springdoc-openapi-starter-webmvc-ui 2.x系列仅适配Spring Boot 3.x。如果你的项目依赖的是Spring Boot 2.x,请替换为SpringDoc 1.x版本的依赖:<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.6.15</version> </dependency>放行Swagger相关路径(若有拦截器/Spring Security)
如果项目中配置了Spring Security或自定义拦截器,需要允许Swagger的静态资源和接口请求通过。以Spring Security为例,添加配置:@Configuration public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth .requestMatchers("/swagger-ui/**", "/v3/api-docs/**") .permitAll() .anyRequest() .authenticated() ); return http.build(); } }移除@EnableWebMvc注解
若你的配置类中添加了@EnableWebMvc,会覆盖Spring Boot的自动Web配置,导致Swagger UI的静态资源无法被正确映射,直接移除该注解即可。检查自定义路径配置
若你在application.properties/yaml中配置了springdoc.swagger-ui.path,比如:springdoc.swagger-ui.path=/docs则需要访问你自定义的路径
/docs/index.html。
内容的提问来源于stack exchange,提问作者Gwendal
相关产品推荐
相关产品推荐

