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();
重啓即可。