解决SpringBoot整合Swagger报错o.s.web.servlet.PageNotFound No mapping for GET的问题

问题

o.s.web.servlet.PageNotFound : No mapping for GET

解决

目前本人遇到这4种情况,后续有再补充,对号入座~
①重定向给
②注解的问题
③SwaggerConfig配置类
④CorsConfig跨域配置

①重定向

/**
 * 解决swagger死循环问题
 * 视具体情况用,若控制台报错 No mapping for GET /aifruit/null/swagger-resources/configuration/security
 * 则使用下面代码
 * 下面这几个地址会一直轮询,改为重定向
 * /null/swagger-resources/configuration/ui
 * /null/swagger-resources/configuration/security
 * /null/swagger-resources
 */
@Override
public void addViewControllers(ViewControllerRegistry registry) {
    
    
    registry.addRedirectViewController("/null/api-docs",
            "/api-docs").setKeepQueryParams(true);
    registry.addRedirectViewController("/null/swagger-resources/configuration/ui",
            "/swagger-resources/configuration/ui");
    registry.addRedirectViewController("/null/swagger-resources/configuration/security",
            "/swagger-resources/configuration/security");
    registry.addRedirectViewController("/null/swagger-resources", "/swagger-resources");
}

②注解问题

  1. 可能是类的@RequestMapping("xxxx")中的xxxx访问路径配置错误
  • 解决方法:检查访问的URL是否正确
  1. 可能是方法的@PostMapping@GetMapping没写或写错
    在这里插入图片描述

③SwaggerConfig配置类

SwaggerConfig配置类缺少一些东西,检查一下:

  • @Configuration
  • @EnableSwagger2
  • .apis(RequestHandlerSelectors.basePackage("com.melodyjerry.config"))
    在这里插入图片描述

④CorsConfig跨域配置

可能是加了拦截器后才反生这样情况,应该是拦截器没有能够成功加载资源文件。将WebMvcConfigurationSupport修改为WebMvcConfigurerAdapter就可以了。
在这里插入图片描述

参考资料

[1] Annotation Configuration Replacement for mvc:resources - Spring

猜你喜欢

转载自blog.csdn.net/weixin_43438052/article/details/114313208
今日推荐