@Configuration
@ConditionalOnProperty(prefix="hsweb.cors",
name="enable",
havingValue="true")
@EnableConfigurationProperties(value=CorsProperties.class)
public class CorsAutoConfiguration
extends Object
Example:
hsweb:
cors:
enable: true
configs:
- /**:
allowed-headers: "*"
allowed-methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
allowed-origins: ["http://xxx.example.com"]
allow-credentials: true
maxAge: 1800
enable设为true,但是configs未配置,将使用已下的默认配置:
hsweb:
cors:
enable: true
configs:
- /**:
allowed-headers: "*"
allowed-methods: ["GET", "POST", "HEAD"]
allowed-origins: "*"
allow-credentials: true
maxAge: 1800
注意:
配置文件中对象的属性名在 SpringBoot 2.x 版本开始不在支持特殊字符,会将特殊字符过滤掉,
仅支持[A-Za-z0-9\-\_],具体细节请查看ConfigurationPropertyName类的adapt方法
Copyright © 2016–2021. All rights reserved.