Spring Boot应用程序配置中的ʻaddCorsMapping`未设置标头

时间:2019-03-03 17:17:05

标签: spring spring-boot kotlin

我有一个(kotlin)Spring Boot配置类,可以执行此操作:

@Bean
fun corsConfigurer(): WebMvcConfigurer {
    return object : WebMvcConfigurer {
        override fun addCorsMappings(registry: CorsRegistry) {
            LOG.info("Configuring CORS")
            registry.addMapping("/**").allowedOrigins("http://localhost:3000")
        }
    }
}

现在,我看到了日志消息,所以我知道该消息正在被调用,但是当我使用cURL提取端点时,我看不到正在添加的CORS标头:

 curl -v localhost:8080/api
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json;charset=UTF-8
< Content-Length: 2
< Date: Sun, 03 Mar 2019 17:15:12 GMT
< 
* Connection #0 to host localhost left intact
OK

根据Spring的本指南,此方法应该有效:https://spring.io/guides/gs/rest-service-cors/

  

springBootVersion ='2.1.2.RELEASE'

0 个答案:

没有答案