1. Error message
has been blocked by CORS policy: No 'Access-Control-Allow-Origin'
header is present on the requested resource.
A page from one IP port (front-end project) needs to access resources on another IP port (springboot request interface), which will generate cross-domain access.
2. Solution: Add configuration class CorsConfig
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedHeaders(CorsConfiguration.ALL)
.allowedMethods(CorsConfiguration.ALL)
.allowCredentials(true)
.maxAge(3600);
}
}