【发布时间】:2016-07-08 14:49:58
【问题描述】:
我正在使用 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);
}
但是当我请求访问令牌时,我仍然看到这个错误
http://localhost:8080/oauth/token?username=admin&password=admin&grant_type=password&scope=read。 对预检请求的响应未通过访问控制检查:否 请求中存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://localhost:9090” 使用权。响应的 HTTP 状态代码为 401。
【问题讨论】:
标签: spring-boot cors yaml jhipster