CORS cause problems Swagger can not be displayed

problem:

Just solve the problem of access to front-end, front-end is able to call, but I can not display the interface of swagger.

 

the reason:

Since the configuration of CORS, swagger interface is built interceptor stopped by.

 

solution:

In your CORS configuration file in, add the following method (the swagger built-in interface on the interceptor's exclusion list)

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

}

 

Published 214 original articles · won praise 281 · views 90000 +

Guess you like

Origin blog.csdn.net/lk1822791193/article/details/103688492