【发布时间】:2020-12-05 02:57:39
【问题描述】:
configure 类的configure 方法中的cors() 过滤器和创建WebMvcConfigurer 的bean 并覆盖addCorsMappings 方法有什么区别?我们什么时候用哪个?谁能解释一下?
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000");
}
};
}
对
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.csrf().disable()
.authorizeRequests()
.mvcMatchers("/rest/**").authenticated()
.anyRequest().permitAll()
.and()
.oauth2ResourceServer().jwt().jwtAuthenticationConverter(this.jwtAuthenticationConverter())
;
}
}
【问题讨论】:
-
也许这个链接可以澄清你的一些疑惑:developpaper.com/…
标签: spring spring-security cors