弹簧启动在生产模式下启动JAR时禁用Bean



我正在使用Spring Boot 1.5.8,并在Application.java中使用以下CORS Filter.java使CORS REST服务可以访问UI开发人员从其本地计算机访问。

  @Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")
                    .allowedHeaders("*", "Access-Control-Allow-Headers", "origin" ,"Content-type","accept", "x-requested-with","x-requested-by") //What is this for?
                    .allowCredentials(true);
        }
    };
}

当我们使用-Dspring.profiles.active=prod

以prod模式启动JAR时,我想自动迁移时禁用此产品。

与bean声明一起添加 @Profile("!prod")。春季配置文件

您可以用@Profile标记任何@Component,因此仅适用于特定配置文件。看看https://docs.spring.io/spring-boot/docs/current/referent/referent/html/boot-features-profiles.html

最新更新