springboot sourcode: 应用程序环境

ConfigurableEnvironment environment = this.prepareEnvironment(listeners//监听器, bootstrapContext//上下文, applicationArguments//参数); //准备环境,获取系统环境,参数等 -> todo
this.configureIgnoreBeanInfo(environment);

private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners, DefaultBootstrapContext bootstrapContext, ApplicationArguments applicationArguments) {
        ConfigurableEnvironment environment = this.getOrCreateEnvironment(); //获取环境 有的话直接获取,没有的话,根据应用类型新建环境
        this.configureEnvironment((ConfigurableEnvironment)environment, applicationArguments.getSourceArgs()); //配置环境:配置属性,配置profile
        ConfigurationPropertySources.attach((Environment)environment);//获取环境属性并验证
        listeners.environmentPrepared(bootstrapContext, (ConfigurableEnvironment)environment);//监听器准备环境 ->
        DefaultPropertiesPropertySource.moveToEnd((ConfigurableEnvironment)environment);//移除默认属性,更新属性
        Assert.state(!((ConfigurableEnvironment)environment).containsProperty("spring.main.environment-prefix"), "Environment prefix cannot be set via properties.");
        this.bindToSpringApplication((ConfigurableEnvironment)environment);//将环境绑定到应用程序
        if (!this.isCustomEnvironment) {
            environment = (new EnvironmentConverter(this.getClassLoader())).convertEnvironmentIfNecessary((ConfigurableEnvironment)environment, this.deduceEnvironmentClass());
        }

        ConfigurationPropertySources.attach((Environment)environment);
        return (ConfigurableEnvironment)environment;
    }

void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
    this.doWithListeners("spring.boot.application.environment-prepared", (listener) -> {
        listener.environmentPrepared(bootstrapContext, environment);
    }); //新建准备环境事件,广播给各监听器,即:各监听器准备环境
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值