环境中没有应用程序属性

时间:2020-02-04 07:05:20

标签: java spring spring-boot

我有一个Spring应用程序中包含的日志记录库。有一个初始化:

package my.project.logger;

import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class MyLibClass implements
    ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        final ConfigurableEnvironment environment = applicationContext.getEnvironment();

        final Binder binder = Binder.get(environment);

        String log = binder.bind("logger.log", Bindable.of(String.class))
            .orElseThrow(() -> new IllegalArgumentException(
                "Mandatory log name is not specified."));
    }
}

仅使用spring-boot-starter-web即可正常运行,但是插入spring-cloud-gcp-starter时则没有这种属性会失败。

请问一下在这里可能出什么问题以及为什么在spring-cloud-gcp-starter的情况下Environment不包含application.properties的原因?

0 个答案:

没有答案