【发布时间】:2018-07-20 10:19:44
【问题描述】:
我们最近将 Spring Boot 从 1.5 迁移到 2.0。迁移后,当我运行应用程序时,会调用自定义上下文侦听器,如果我们在尚未创建的源之前添加属性源,则会在其中使用exit code 1 停止应用程序。
在 Spring Boot 1.5.x 中,ConfigFileApplicationListener 将 applicationConfigurationProperties 添加到可用属性源列表中。
由于某种原因,applicationConfigurationProperties 在迁移后没有被添加,因此以下代码失败:
event.getEnvironment().getPropertySources().addBefore("applicationConfigurationProperties", new MapPropertySource("aws", parameters));
使用 Spring 1.5.x
o.s.w.c.s.StandardServletEnvironment:Adding PropertySource 'aws' with search precedence immediately higher than 'applicationConfigurationProperties'
我也启用了以下日志,但没有看到任何异常:
logging.level.org.springframework=TRACE
logging.level.org.springframework.context=TRACE
logging.level.org.springframework.boot=TRACE
logging.level.org.springframework.core=TRACE
所有应用程序侦听器都实现ApplicationListener<ApplicationEnvironmentPreparedEvent>。
我查看了迁移指南,发现添加了一个新事件,ApplicationStartedEvent,但这应该没有任何区别。
【问题讨论】:
标签: java spring spring-boot