spring boot admin导致swagger-ui.html无法访问的解决办法

spring boot admin版本:2.1.3

swagger2版本:2.7.0

spring boot security版本:2.1.3

问题现象是:spring boot admin可以正常监控了,但是swagger-ui.html却无法打开:

尝试1:重写public void configure(WebSecurity web)

@Override

public void configure(WebSecurity web) {

//allow Swagger URL to be accessed without authentication

web.ignoring().antMatchers("/v2/api-docs",

"/swagger-resources/configuration/ui",

"/swagger-resources",

"/swagger-resources/configuration/security",

"/swagger-ui.html");

}

没有用。

尝试2:更换spring boot admin到2.1.4

仍旧不起作用。

最终解决办法:

1.重写连接器的addResourceHandlers方法:

registry.addResourceHandler("/templates/**.js").addResourceLocations("classpath:/templates/");

registry.addResourceHandler("/templates/**.css").addResourceLocations("classpath:/templates/");

registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

registry.addResourceHandler("swagger-ui.html")

.addResourceLocations("classpath:/META-INF/resources/");

registry.addResourceHandler("/webjars/**")

.addResourceLocations("classpath:/META-INF/resources/webjars/");

2.在安全配置里加入:

http.authorizeRequests().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**","/swagger-resources/configuration/ui").permitAll();

重启即可。

小编这里整理了更多相关的 学习资料和 学习视频,可免费领取。

加 VX:18410263200    通过验证备注:111(备注必填,方便通过)

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容