简体   繁体   English

在运行时重新加载CORS设置

[英]Reloading CORS settings at runtime

I recently implemented a Spring Cloud Config Server . 我最近实现了一个Spring Cloud Config Server My application (client) is able to retrieve application profiles and refresh them in flight. 我的应用程序(客户端)能够检索应用程序配置文件并在运行中刷新它们。 Unfortunately, CORS settings, which are also declared there, are not reloaded by Spring during runtime. 不幸的是,Spring也不会在运行时重新加载在那里也声明的CORS设置。 I did a small investigation and check that in terms of refresh everything looks good - ConfigurationPropertiesRebinder rebind() method successfully destroys old bean holding CORS setup and creates a new with up-to-date settings. 我进行了一次小型调查,并检查了刷新是否一切正常ConfigurationPropertiesRebinder rebind()方法成功销毁了拥有CORS设置的旧bean,并使用最新设置创建了一个新bean。 I also see that Environment bean is holding new settings in propertySources field. 我还看到Environment Bean在propertySources字段中拥有新设置。

Is there any way to force Spring to reload CORS during runtime or should I need to reload application context? 有什么方法可以强制Spring在运行时重新加载CORS,还是应该重新加载应用程序上下文?

Use below code for resolve CORS issue. 使用以下代码解决CORS问题。

@Configuration
@EnableWebMvc
class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM