使用自定义启动器时:
@Configuration
@PropertySource("classpath:monitoring.properties")
@ConditionalOnProperty(value = "xxx.monitoring.enabled",
havingValue = "true",
matchIfMissing = true)
public class MonitoringAutoConfiguration {
private static final String XXX_MONITORING_SERVICE_NAME = "${xxx.monitoring.service-name}";
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(@Value(XXX_MONITORING_SERVICE_NAME)
String serviceName) {
return registry -> registry.config()
.commonTags("application", serviceName);
}
从启动程序中运行集成测试但未设置该值时,我得到:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'xxx.monitoring.service-name' in value "${xxx.monitoring.service-name}
启动器在主项目中启动时,不会像我期望的那样崩溃,而是将值解析为:
“ $ {xxx.monitoring.service-name}” ,是故意的吗?就我而言,我更希望应用程序崩溃而不是使用未解决的指标崩溃,它可以添加验证,但是这种行为令人惊讶,我知道配置属性,但事实并非如此。
答案 0 :(得分:0)
我认为这是因为应用程序启动用于集成测试和主要项目的配置文件不同