小编Nea*_*leU的帖子

CORS Origin Spring Boot Jhipster - 飞行前失败

我正在使用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
Run Code Online (Sandbox Code Playgroud)

在"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);
    }
Run Code Online (Sandbox Code Playgroud)

但是当我请求访问令牌时,我看到了这个错误

http:// localhost:8080/oauth/token?username = admin&password = admin&grant_type = password&scope = read.对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许来源' …

yaml cors spring-boot jhipster

4
推荐指数
1
解决办法
5950
查看次数

标签 统计

cors ×1

jhipster ×1

spring-boot ×1

yaml ×1