spring cloud bootstrap配置

  1. spring.cloud.bootstrap.name默认为bootstrap
  2. spring.cloud.bootstrap.location默认为resources目录下 如果设置为config 这代表resources/config
  3. spring.cloud.config.allowOverride
    如果想要远程配置优先级高,那么allowOverride设置为false,如果想要本地配置优先级高那么allowOverride设置为true
    spring.cloud.config.allowOverride=true
  4. spring.cloud.config.overrideNone
    overrideNone为true时本地配置优先级高,包括系统环境变量、本地配置文件等等
    spring.cloud.config.overrideNone=true
  5. spring.cloud.config.overrideSystemProperties
    只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置
    spring.cloud.config.overrideSystemProperties=true
@SpringBootConfiguration
public class KimServerApplication {

    private static final String SPRING_CONFIG_NAME_KEY = "--spring.cloud.bootstrap.name";
    private static final String DEFAULT_SPRING_CONFIG_PARAM = SPRING_CONFIG_NAME_KEY + "=" + "kim";

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

    private static String[] updateArguments(String[] args) {
        if (Arrays.stream(args).noneMatch(arg -> arg.startsWith(SPRING_CONFIG_NAME_KEY))) {
            String[] modifiedArgs = new String[args.length + 1];
            System.arraycopy(args, 0, modifiedArgs, 0, args.length);
            modifiedArgs[args.length] = DEFAULT_SPRING_CONFIG_PARAM;
            return modifiedArgs;
        }
        return args;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。