gpt4 book ai didi

spring-boot - CORS Origin Spring Boot Jhipster - 飞行前失败

转载 作者:行者123 更新时间:2023-12-04 23:41:29 25 4
gpt4 key购买 nike

我正在使用 jhipster v2.27.2
我通过取消注释 application.yml 中的行来启用 cors

jhipster:
async:
corePoolSize: 2
maxPoolSize: 50
queueCapacity: 10000

cors: #By default CORS are not enabled. Uncomment to enable.
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800

在“WebConfigurer”中
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = props.getCors();
if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
source.registerCorsConfiguration("/api/**", config);
source.registerCorsConfiguration("/v2/api-docs", config);
source.registerCorsConfiguration("/oauth/**", config);
}
return new CorsFilter(source);
}

但是当我请求访问 token 时,我仍然看到这个错误

http://localhost:8080/oauth/token?username=admin&password=admin&grant_type=password&scope=read. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9090' is therefore not allowed access. The response had HTTP status code 401.

最佳答案

看起来像在默认 SecurityConfiguration ,它不会跳过 OPTIONS 的安全检查。

尝试添加以下内容 antMatcherprotected void configure(HttpSecurity http) SecurityConfiguration.java 中的方法

.antMatchers(org.springframework.http.HttpMethod.OPTIONS, "/api/**").permitAll()

关于spring-boot - CORS Origin Spring Boot Jhipster - 飞行前失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36142155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com