我的Spring Boot Rest API由JWT令牌保护 . 我有以下CORS设置

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {  registry.addMapping("/api/**").allowedMethods("*").allowedOrigins("*").maxAge(3600);}};
}

并在安全配置中

httpSecurity.authorizeRequests().antMatchers("/api/public/**").permitAll();
        httpSecurity.authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll();
        httpSecurity.antMatcher("/api/**").authorizeRequests().anyRequest().authenticated().and().exceptionHandling()
                .authenticationEntryPoint(restAuthenticationEntryPoint)

现在我能够验证并获取JWT令牌,获取,发布我在不同域中运行的角度2应用程序的数据 . 现在我想通过捕获HTTP状态401来处理令牌到期 . 当令牌过期时,我从 Spring 季启动获得状态401 . 但401错误没有达到角度,因为浏览器抱怨CORS

无法加载http:// ipaddress:8010 / api / sy / code / findAll?page = 0:请求的资源上没有“Access-Control-Allow-Origin”标头 . 因此不允许来源'http:// localhost:4200'访问 . 响应具有HTTP状态代码401

如何配置spring boot以发送401的Access-control-Allow-origin . 我确实允许allowOrigins(“*”)配置 . 但这似乎不起作用 . 任何帮助 .