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
- It may be
@RequestMapping("xxxx")
that thexxxx
access path in the class is misconfigured
- Solution: Check whether the accessed URL is correct
- It may be methodological
@PostMapping
or@GetMapping
not written or written wrong
③SwaggerConfig configuration class
SwaggerConfig
The configuration class is missing something, check it:
@Configuration
@EnableSwagger2
.apis(RequestHandlerSelectors.basePackage("com.melodyjerry.config"))
④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 WebMvcConfigurationSupport
modified to WebMvcConfigurerAdapter
it.
Reference
[1] Annotation Configuration Replacement for mvc:resources - Spring