When i make a GET or POST request to my rest api i get Vary:origin header but i actually need Access-Control-Allow-Origin header
i have these:
Security config class:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.authorizeRequests()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilterBefore(authenticationTokenFilterBean(),UsernamePasswordAuthenticationFilter.class);
}
}
Cors configuration class
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("GET", "POST")
.allowedOrigins("*")
.allowedHeaders("Content_Type", "Authorization");
}
}
question from:
https://stackoverflow.com/questions/65944988/access-control-allow-origin-header-is-missing-spring-boot-cors 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…