Spring Boot整合Security+Swagger2踩坑记录,Swagger2无法访问首页

问题: 访问不了Swagger的页面


有可能出现的原因:
1.Security将访问拦截掉了
2.给拦截器拦截了
3.Swagger返回的结果,被自己定义的拦截器or其他方式给篡改了数据,导致无法正常显示,也就无法得到想要的结果
 

解决:
1.放开访问
 

                //忽略swagger访问权限限制
                .antMatchers(
                        "/userlogin",
                        "/userlogout",
                        "/userjwt",
                        "/v2/api-docs",
                        "/swagger-resources/configuration/ui",
                        "/swagger-resources",
                        "/swagger-resources/configuration/security",
                        "/swagger-ui.html",
                        "/css/**",
                        "/js/**",
                        "/images/**",
                        "/webjars/**",
                        "/import/test",
                        "**/favicon.ico",
                        "/index").permitAll()

2.放开资源
 

	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("swagger-ui.html")
				.addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**")
				.addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

3.注意返回数据是否篡改,我这里是自定义advice导致的,例如下图,我必须只扫描controller,不然会导致数据出现问题

@RestControllerAdvice(basePackages = "com.happy.football.controller")

 


版权声明:本文为baidu_38990811原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。