📜  ro 如何从 webmvc allowedOrigins 中的应用程序属性中获取价值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:40.088000             🧑  作者: Mango

代码示例1
@SpringBootApplication
public class App extends SpringBootServletInitializer {

    @Autowired
    private Environment env;

    public static void main(String[] args) {
        SpringApplication.run(ReportsApplication.class, args);
    }

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                String urls = env.getProperty("cors.urls");
                CorsRegistration reg = registry.addMapping("/api/**");
                for(String url: urls.split(",")) {
                    reg.allowedOrigins(url);
                }
            }
        };
    }    
}