org.springframework.web.context.ContextLoader:324) - Context initialization failed java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment...runjettyrun.Bootstrap.main(Bootstrap.java:275) Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.ConfigurableEnvironment...runjettyrun.HSFJettyWebAppContext@6623a0d3{/,src/main/webapp}: java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment...58:25.075:WARN::Error starting handlers java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment
这里我们要用到ConfigurableEnviroment 这个类,我们来看一下源码 public interface ConfigurableEnvironment extends Environment...getSystemProperties(); // 获取系统环境变量 Map getSystemEnvironment(); void merge(ConfigurableEnvironment...LOG = LoggerFactory.getLogger(PropertiesEncryptionConfig.class); // 在通过@bean 注入进来 public ConfigurableEnvironment...environment ; public PropertiesEncryptionConfig(ConfigurableEnvironment environment) {...configurableEnvironment){ return new PropertiesEncryptionConfig(configurableEnvironment);
ConfigurableEnvironment:继承自ConfigurablePropertyResolver和Environment,并且提供设置激活的profile和默认的profile的功能。...ConfigurableWebEnvironment:继承自ConfigurableEnvironment,并且提供配置Servlet上下文和Servlet参数的功能。...AbstractEnvironment:实现了ConfigurableEnvironment接口,默认属性和存储容器的定义,并且实现了ConfigurableEnvironment种的方法,并且为子类预留可覆盖了扩展方法...实例 ConfigurableEnvironment environment = getOrCreateEnvironment(); //启动参数绑定到ConfigurableEnvironment...加载完毕之后,ConfigurableEnvironment中基本包含了所有需要加载的属性(activeProfiles是这个时候被写入ConfigurableEnvironment)。
try { ApplicationArguments applicationArguments = new DefaultApplicationArguments( args); ConfigurableEnvironment...对象 准备运行时环境 private ConfigurableEnvironment prepareEnvironment( SpringApplicationRunListeners listeners..., ApplicationArguments applicationArguments) { ConfigurableEnvironment environment = getOrCreateEnvironment...(environment); } return environment; } 获取或创建环境getOrCreateEnvironment 方法名就很直观,有就直接获取,没有就新建 private ConfigurableEnvironment..., environment); MutablePropertySources sources = ((ConfigurableEnvironment) environment) .getPropertySources
private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners, ApplicationArguments...applicationArguments) { ConfigurableEnvironment environment = this.getOrCreateEnvironment();...this.configureEnvironment((ConfigurableEnvironment)environment, applicationArguments.getSourceArgs...()); //配置信息准备好的广播消息 listeners.environmentPrepared((ConfigurableEnvironment)environment...); //将配置绑定到springApplication上 this.bindToSpringApplication((ConfigurableEnvironment)environment
private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners, DefaultBootstrapContext...bootstrapContext, ApplicationArguments applicationArguments) { //创建并配置环境 ConfigurableEnvironment environment...= null) { return this.environment; } //根据web应用程序类型,通过applicationContextFactory创建environment ConfigurableEnvironment...public ConfigurableEnvironment createEnvironment(WebApplicationType webApplicationType) { //不是Web Servlet..., environment); MutablePropertySources sources = ((ConfigurableEnvironment) environment).getPropertySources
前面我们写了使用自定义的加载properties 的代码 里面实现了 EnvironmentPostProcessor @Override public void postProcessEnvironment(ConfigurableEnvironment...下面我们开看刷新Environment 的代码实现 public static void refreshEnvironment(Map map,ConfigurableEnvironment...configurableEnvironment) { MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources...private ConfigurablePropertyResolver configurablePropertyResolver; @Autowired private ConfigurableEnvironment...configurableEnvironment; @Autowired private Person person; /** * 动态刷新参数接口 *
args); // 开始 listeners.starting(); // 处理所有 property sources 配置和 profiles 配置,准备环境,分为标准 Servlet 环境和标准环境 ConfigurableEnvironment...* @param environment the environment */ void environmentPrepared(ConfigurableEnvironment...3.2 prepareEnvironment(listeners, applicationArguments); 创建 ConfigurableEnvironment;将配置的环境绑定到Spring Application...中; private ConfigurableEnvironment prepareEnvironment( SpringApplicationRunListeners...ApplicationArguments applicationArguments) { // Create and configure the environment ConfigurableEnvironment
SpringApplication对象以及SpringApplication.run方法执行的内容,今天主要细讲的是SpringApplication.run中的准备环境的prepareEnvironment方法源码ConfigurableEnvironment...DefaultBootstrapContext bootstrapContext, ApplicationArguments applicationArguments) { // 创建和配置环境 ConfigurableEnvironment...convertEnvironment(environment); } ConfigurationPropertySources.attach(environment); //返回环境配置对象ConfigurableEnvironment...bindToSpringApplication将环境配置参数绑定到SpringApplication convertEnvironment 如果isCustomEnvironment为false则将ConfigurableEnvironment...application environment并且不直接解析配置文件属性的应用程序环境 最后再执行一次ConfigurationPropertySources.attach,完成之后返回环境配置对象ConfigurableEnvironment
; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.env.ConfigurableEnvironment...public static final String AES_SECRET = "OneMore"; @Override public void postProcessEnvironment(ConfigurableEnvironment...import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment...EnvironmentPostProcessor实现类的实例 * @param properties 预置准备做单元测试的属性 * @return 处理过的Environment */ private ConfigurableEnvironment...ConfigurableApplicationContext context = springApplication.run(); // 获取Environment ConfigurableEnvironment
locations[i]).trim(); } } else { this.configLocations = null; } } setConfigLocations主要工作有两个:创建环境对象ConfigurableEnvironment...、处理ClassPathXmlApplicationContext传入的字符串中的占位符; 环境对象ConfigurableEnvironment中包含了当前JVM的profile配置信息、环境变量、...Java进程变量; 处理占位符的关键是ConfigurableEnvironment、PropertyResolver、PropertyPlaceholderHelper之间的配合 // 这个方法的目的是替换掉.../ 2.进入resolveRequiredPlaceholders方法 return getEnvironment().resolveRequiredPlaceholders(path); } 1.ConfigurableEnvironment... getEnvironment():创建了ConfigurableEnvironment 对象 public ConfigurableEnvironment getEnvironment() {
ConfigFileApplicationListener的postProcessEnvironment,如下List-2所示: List-2 @Override public void postProcessEnvironment(ConfigurableEnvironment...addPropertySources(environment, application.getResourceLoader()); } ... protected void addPropertySources(ConfigurableEnvironment...Loader(ConfigurableEnvironment environment, ResourceLoader resourceLoader) { this.environment = environment...List-7 private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners,ApplicationArguments...applicationArguments) { // Create and configure the environment ConfigurableEnvironment environment
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment...configurableEnvironment = applicationContext.getEnvironment(); Map map = new...@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment...configurableEnvironment = applicationContext.getEnvironment(); Map map = new...configurableEnvironment = applicationContext.getEnvironment(); Map map = new
准备环境prepareEnvironment,创建环境完成后回调SpringApplicationRunListeners.environmentPrepared():表示环境准备完成 private ConfigurableEnvironment...environment = this.getOrCreateEnvironment(); this.configureEnvironment((ConfigurableEnvironment...)environment, applicationArguments.getSourceArgs()); listeners.environmentPrepared((ConfigurableEnvironment...)environment); this.bindToSpringApplication((ConfigurableEnvironment)environment); if...; } ConfigurationPropertySources.attach((Environment)environment); return (ConfigurableEnvironment
进入 configureEnvironment((ConfigurableEnvironment)environment, applicationArguments.getSourceArgs())方法...类型 Assert.isInstanceOf(ConfigurableEnvironment.class, environment); // 获取 Environment...的属性集 MutablePropertySources sources = ((ConfigurableEnvironment)environment).getPropertySources...进入 environmentPrepared(ConfigurableEnvironment environment)方法 -- EventPublishingRunListener类 只获取到一个...进入 bindToSpringApplication((ConfigurableEnvironment)environment)方法 该方法的作用是将 spring.main 开头的属性绑定到当前的
ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments...我们看一下prepareEnvironment方法 private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners...(); this.configureEnvironment((ConfigurableEnvironment)environment, applicationArguments.getSourceArgs...this.bindToSpringApplication((ConfigurableEnvironment)environment); if (!...private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment
args); // 开始 listeners.starting(); // 处理所有 property sources 配置和 profiles 配置,准备环境,分为标准 Servlet 环境和标准环境 ConfigurableEnvironment...* @param environment the environment */ void environmentPrepared(ConfigurableEnvironment...3.2 prepareEnvironment(listeners, applicationArguments); 创建 ConfigurableEnvironment; 将配置的环境绑定到Spring...Application中; private ConfigurableEnvironment prepareEnvironment( SpringApplicationRunListeners...ApplicationArguments applicationArguments) { // Create and configure the environment ConfigurableEnvironment
username; private String password; private String prefix; private Boolean primary=false; private ConfigurableEnvironment...environment; private static String propertyBase="datasource"; public DataSourceProperties(ConfigurableEnvironment...String getPassword() { return password; } public String getPrefix() { return prefix; } public ConfigurableEnvironment...the dynamic beans. */ @Bean static BeanDefinitionRegistryPostProcessor beanPostProcessor(final ConfigurableEnvironment...,prefix)); } } } } return propertyMap; } static private void createDynamicBeans(ConfigurableEnvironment
param application the application to which the environment belongs */ void postProcessEnvironment(ConfigurableEnvironment...application); } springboot提供了EnvironmentPostProcessor接口,该接口有postProcessEnvironment方法,其中envrionment参数类型为ConfigurableEnvironment...private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment...YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); @Override public void postProcessEnvironment(ConfigurableEnvironment
领取专属 10元无门槛券
手把手带您无忧上云