【发布时间】:2021-09-24 05:24:33
【问题描述】:
我正在开发一个基于 Web 的应用程序,该应用程序带有 angular 和 spring boot。 Jwt 已生成,用户可以登录,他可以看到他的信息,但是当我想编辑用户信息时,它会在浏览器上显示此错误:
user:1 从源“http://localhost:4200”访问“http://localhost:8080/api/user”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应没有“ t 通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
在 IntelliJ 中,它说:JWT 令牌不以 Bearer String 开头
我用过: httpSecurity.cors().and().csrf().disable()
和
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Arrays.asList("http://localhost:4200"));
config.setAllowedMethods(Arrays.asList("GET", "POST", "OPTIONS", "DELETE", "PUT", "PATCH"));
config.setAllowCredentials(true);
config.setAllowedHeaders(Arrays.asList("Authorization", "Cache-Control", "Content-Type"));
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}
在更新用户信息时仍然遇到问题。
【问题讨论】:
标签: java angular spring spring-boot jwt