Solve the problem of SpringBoot integration Swagger reporting error osweb.servlet.PageNotFound No mapping for GET

problem

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

solve

Currently I met these four cases, we have to add the follow-up, the condemnation ~
① redirected to the
problem ② annotations
③SwaggerConfig configuration class
④CorsConfig cross-domain configuration

①Redirect

/**
 * 解决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");
}

②Annotation problem

  1. It may be @RequestMapping("xxxx")that the xxxxaccess path in the class is misconfigured
  • Solution: Check whether the accessed URL is correct
  1. It may be methodological @PostMappingor @GetMappingnot written or written wrong
    Insert picture description here

③SwaggerConfig configuration class

SwaggerConfigThe configuration class is missing something, check it:

  • @Configuration
  • @EnableSwagger2
  • .apis(RequestHandlerSelectors.basePackage("com.melodyjerry.config"))
    Insert picture description here

④CorsConfig cross-domain configuration

This may happen after the interceptor is added. It should be that the interceptor failed to load the resource file successfully. Will be WebMvcConfigurationSupportmodified to WebMvcConfigurerAdapterit.
Insert picture description here

Reference

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

Guess you like

Origin blog.csdn.net/weixin_43438052/article/details/114313208
Recommended