问题
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");
}
②注解问题
- 可能是类的
@RequestMapping("xxxx")
中的xxxx
访问路径配置错误
- 解决方法:检查访问的URL是否正确
- 可能是方法的
@PostMapping
或@GetMapping
没写或写错
③SwaggerConfig配置类
SwaggerConfig
配置类缺少一些东西,检查一下:
@Configuration
@EnableSwagger2
.apis(RequestHandlerSelectors.basePackage("com.melodyjerry.config"))
④CorsConfig跨域配置
可能是加了拦截器后才反生这样情况,应该是拦截器没有能够成功加载资源文件。将WebMvcConfigurationSupport
修改为WebMvcConfigurerAdapter
就可以了。
参考资料
[1] Annotation Configuration Replacement for mvc:resources - Spring