diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java index 550a9d634..1f220769d 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/MetadataContextHolder.java @@ -56,20 +56,20 @@ private MetadataContextHolder() { } public static MetadataContext get() { - try { - return (MetadataContext) com.tencent.polaris.metadata.core.manager.MetadataContextHolder.getOrCreate(); - } - catch (Throwable throwable) { - LOG.error("Failed to get or create MetadataContext.", throwable); - return null; - } + return (MetadataContext) com.tencent.polaris.metadata.core.manager.MetadataContextHolder.getOrCreate(); } private static MetadataContext createMetadataManager() { MetadataContext metadataManager = new MetadataContext(); if (staticMetadataManager == null) { - staticMetadataManager = ApplicationContextAwareUtils.getApplicationContext() - .getBean(StaticMetadataManager.class); + if (ApplicationContextAwareUtils.getApplicationContext() != null) { + staticMetadataManager = ApplicationContextAwareUtils.getApplicationContext() + .getBean(StaticMetadataManager.class); + } + else { + // for junit test. + return metadataManager; + } } // local custom metadata MetadataContainer metadataContainer = metadataManager.getMetadataContainer(MetadataType.CUSTOM, false);