@Configuration
public class CorsConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH").allowedOrigins("*")
.allowedHeaders("*");
}
};
}
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors()
.and().csrf()
.disable().authorizeRequests().antMatchers("/",
"/favicon.ico",
"/**/*.png",
"/**/*.gif",
"/**/*.svg",
"/**/*.jpg",
"/**/*.html",
"/**/*.css",
"/**/*.js")
.permitAll()
.antMatchers("/registration", "/login")
.permitAll().anyRequest()
.authenticated();;
}
从reactjs发送请求时,我在屏幕截图中看到了错误。我认为这与CrossOrigin问题有关。请帮助