From ede38f4176564865a427226255fb0b4cac96506b Mon Sep 17 00:00:00 2001 From: wulingxiao <1251605638@qqcom> Date: Mon, 25 Jul 2022 21:37:22 +0800 Subject: [PATCH] feature:support spring cloud configData --- .../adapter/PolarisConfigFilePuller.java | 196 +++++++++++++++++- .../configdata/PolarisConfigDataLoader.java | 6 +- ...igDataMissingEnvironmentPostProcessor.java | 17 ++ .../configdata/PolarisConfigDataResource.java | 115 +++++++++- ...itional-spring-configuration-metadata.json | 6 + 5 files changed, 335 insertions(+), 5 deletions(-) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFilePuller.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFilePuller.java index 2899d913b..a4f7787e6 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFilePuller.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFilePuller.java @@ -1 +1,195 @@ -/* * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. * * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the BSD 3-Clause License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-3-Clause * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package com.tencent.cloud.polaris.config.adapter; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import com.tencent.cloud.polaris.config.config.ConfigFileGroup; import com.tencent.cloud.polaris.config.configdata.PolarisConfigDataLoader; import com.tencent.cloud.polaris.config.enums.ConfigFileFormat; import com.tencent.cloud.polaris.context.config.PolarisContextProperties; import com.tencent.polaris.configuration.api.core.ConfigFileMetadata; import com.tencent.polaris.configuration.api.core.ConfigFileService; import com.tencent.polaris.configuration.api.core.ConfigKVFile; import com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.CompositePropertySource; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** * PolarisConfigFilePuller pull configFile from Polaris. * * @author wlx */ public final class PolarisConfigFilePuller { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigFileLocator.class); private PolarisContextProperties polarisContextProperties; private ConfigFileService configFileService; private PolarisPropertySourceManager polarisPropertySourceManager; private PolarisConfigFilePuller() { } /** * InitInternalConfigFiles for {@link PolarisConfigDataLoader}. * * @param compositePropertySource compositePropertySource * @param activeProfiles activeProfiles * @param serviceName serviceName */ public void initInternalConfigFiles(CompositePropertySource compositePropertySource, String[] activeProfiles, String serviceName) { List internalConfigFiles = getInternalConfigFiles(activeProfiles, serviceName); for (ConfigFileMetadata configFile : internalConfigFiles) { PolarisPropertySource polarisPropertySource = loadPolarisPropertySource( configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName()); compositePropertySource.addPropertySource(polarisPropertySource); polarisPropertySourceManager.addPropertySource(polarisPropertySource); LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile); } } /** * Init multiple CustomPolarisConfigFile. * * @param compositePropertySource compositePropertySource * @param configFileGroups configFileGroups */ public void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource, List configFileGroups) { configFileGroups.forEach( configFileGroup -> initCustomPolarisConfigFile(compositePropertySource, configFileGroup) ); } /** * Init single CustomPolarisConfigFile. * * @param compositePropertySource compositePropertySource * @param configFileGroup configFileGroup */ public void initCustomPolarisConfigFile(CompositePropertySource compositePropertySource, ConfigFileGroup configFileGroup) { String namespace = polarisContextProperties.getNamespace(); String group = configFileGroup.getName(); if (!StringUtils.hasText(group)) { throw new IllegalArgumentException("polaris config group name cannot be empty."); } List files = configFileGroup.getFiles(); if (CollectionUtils.isEmpty(files)) { return; } for (String fileName : files) { PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(namespace, group, fileName); compositePropertySource.addPropertySource(polarisPropertySource); polarisPropertySourceManager.addPropertySource(polarisPropertySource); LOGGER.info( "[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}", namespace, group, fileName); } } private PolarisPropertySource loadPolarisPropertySource(String namespace, String group, String fileName) { ConfigKVFile configKVFile; // unknown extension is resolved as properties file if (ConfigFileFormat.isPropertyFile(fileName) || ConfigFileFormat.isUnknownFile(fileName)) { configKVFile = configFileService.getConfigPropertiesFile(namespace, group, fileName); } else if (ConfigFileFormat.isYamlFile(fileName)) { configKVFile = configFileService.getConfigYamlFile(namespace, group, fileName); } else { LOGGER.warn("[SCT Config] Unsupported config file. namespace = {}, group = {}, fileName = {}", namespace, group, fileName); throw new IllegalStateException("Only configuration files in the format of properties / yaml / yaml" + " can be injected into the spring context"); } Map map = new ConcurrentHashMap<>(); for (String key : configKVFile.getPropertyNames()) { map.put(key, configKVFile.getProperty(key, null)); } return new PolarisPropertySource(namespace, group, fileName, configKVFile, map); } private List getInternalConfigFiles(String[] activeProfiles, String serviceName) { String namespace = polarisContextProperties.getNamespace(); if (StringUtils.hasText(polarisContextProperties.getService())) { serviceName = polarisContextProperties.getService(); } // priority: application-${profile} > application > boostrap-${profile} > boostrap return getInternalConfigFiles(activeProfiles, namespace, serviceName); } private List getInternalConfigFiles(String[] activeProfiles, String namespace, String serviceName) { List internalConfigFiles = new LinkedList<>(); for (String activeProfile : activeProfiles) { if (!StringUtils.hasText(activeProfile)) { continue; } internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + activeProfile + ".properties")); internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + activeProfile + ".yml")); } internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties")); internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml")); for (String activeProfile : activeProfiles) { if (!StringUtils.hasText(activeProfile)) { continue; } internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + activeProfile + ".properties")); internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + activeProfile + ".yml")); } internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties")); internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml")); return internalConfigFiles; } /** * Factory method to create PolarisConfigFilePuller for * {@link PolarisConfigDataLoader},{@link PolarisConfigFileLocator}. * * @param polarisContextProperties polarisContextProperties * @param configFileService configFileService * @param polarisPropertySourceManager polarisPropertySourceManager * @return PolarisConfigFilePuller instance */ public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager) { PolarisConfigFilePuller puller = new PolarisConfigFilePuller(); puller.polarisContextProperties = polarisContextProperties; puller.configFileService = configFileService; puller.polarisPropertySourceManager = polarisPropertySourceManager; return puller; } } \ No newline at end of file +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.config.adapter; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.tencent.cloud.polaris.config.config.ConfigFileGroup; +import com.tencent.cloud.polaris.config.configdata.PolarisConfigDataLoader; +import com.tencent.cloud.polaris.config.enums.ConfigFileFormat; +import com.tencent.cloud.polaris.context.config.PolarisContextProperties; +import com.tencent.polaris.configuration.api.core.ConfigFileMetadata; +import com.tencent.polaris.configuration.api.core.ConfigFileService; +import com.tencent.polaris.configuration.api.core.ConfigKVFile; +import com.tencent.polaris.configuration.client.internal.DefaultConfigFileMetadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.core.env.CompositePropertySource; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +/** + * PolarisConfigFilePuller pull configFile from Polaris. + * + * @author wlx + */ +public final class PolarisConfigFilePuller { + + private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigFileLocator.class); + + private PolarisContextProperties polarisContextProperties; + + private ConfigFileService configFileService; + + private PolarisPropertySourceManager polarisPropertySourceManager; + + private PolarisConfigFilePuller() { + } + + /** + * InitInternalConfigFiles for {@link PolarisConfigDataLoader}. + * + * @param compositePropertySource compositePropertySource + * @param activeProfiles activeProfiles + * @param serviceName serviceName + */ + public void initInternalConfigFiles(CompositePropertySource compositePropertySource, String[] activeProfiles, String serviceName) { + List internalConfigFiles = getInternalConfigFiles(activeProfiles, serviceName); + for (ConfigFileMetadata configFile : internalConfigFiles) { + PolarisPropertySource polarisPropertySource = loadPolarisPropertySource( + configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName()); + compositePropertySource.addPropertySource(polarisPropertySource); + polarisPropertySourceManager.addPropertySource(polarisPropertySource); + LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile); + } + } + + /** + * Init multiple CustomPolarisConfigFile. + * + * @param compositePropertySource compositePropertySource + * @param configFileGroups configFileGroups + */ + public void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource, + List configFileGroups) { + configFileGroups.forEach( + configFileGroup -> initCustomPolarisConfigFile(compositePropertySource, configFileGroup) + ); + } + + /** + * Init single CustomPolarisConfigFile. + * + * @param compositePropertySource compositePropertySource + * @param configFileGroup configFileGroup + */ + public void initCustomPolarisConfigFile(CompositePropertySource compositePropertySource, +ConfigFileGroup configFileGroup) { + String namespace = polarisContextProperties.getNamespace(); + String group = configFileGroup.getName(); + if (!StringUtils.hasText(group)) { + throw new IllegalArgumentException("polaris config group name cannot be empty."); + } + List files = configFileGroup.getFiles(); + if (CollectionUtils.isEmpty(files)) { + return; + } + for (String fileName : files) { + PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(namespace, group, fileName); + compositePropertySource.addPropertySource(polarisPropertySource); + polarisPropertySourceManager.addPropertySource(polarisPropertySource); + LOGGER.info( + "[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}", + namespace, group, fileName); + } + } + + private PolarisPropertySource loadPolarisPropertySource(String namespace, String group, String fileName) { + ConfigKVFile configKVFile; + // unknown extension is resolved as properties file + if (ConfigFileFormat.isPropertyFile(fileName) + || ConfigFileFormat.isUnknownFile(fileName)) { + configKVFile = configFileService.getConfigPropertiesFile(namespace, group, fileName); + } + else if (ConfigFileFormat.isYamlFile(fileName)) { + configKVFile = configFileService.getConfigYamlFile(namespace, group, fileName); + } + else { + LOGGER.warn("[SCT Config] Unsupported config file. namespace = {}, group = {}, fileName = {}", namespace, + group, fileName); + + throw new IllegalStateException("Only configuration files in the format of properties / yaml / yaml" + + " can be injected into the spring context"); + } + Map map = new ConcurrentHashMap<>(); + for (String key : configKVFile.getPropertyNames()) { + map.put(key, configKVFile.getProperty(key, null)); + } + return new PolarisPropertySource(namespace, group, fileName, configKVFile, map); + } + + + private List getInternalConfigFiles(String[] activeProfiles, String serviceName) { + String namespace = polarisContextProperties.getNamespace(); + if (StringUtils.hasText(polarisContextProperties.getService())) { + serviceName = polarisContextProperties.getService(); + } + // priority: application-${profile} > application > boostrap-${profile} > boostrap + return getInternalConfigFiles(activeProfiles, namespace, serviceName); + } + + private List getInternalConfigFiles(String[] activeProfiles, String namespace, String serviceName) { + List internalConfigFiles = new LinkedList<>(); + for (String activeProfile : activeProfiles) { + if (!StringUtils.hasText(activeProfile)) { + continue; + } + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + activeProfile + ".properties")); + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + activeProfile + ".yml")); + } + + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties")); + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml")); + + for (String activeProfile : activeProfiles) { + if (!StringUtils.hasText(activeProfile)) { + continue; + } + + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + activeProfile + ".properties")); + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + activeProfile + ".yml")); + } + + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties")); + internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml")); + + return internalConfigFiles; + } + + /** + * Factory method to create PolarisConfigFilePuller for + * {@link PolarisConfigDataLoader},{@link PolarisConfigFileLocator}. + * + * @param polarisContextProperties polarisContextProperties + * @param configFileService configFileService + * @param polarisPropertySourceManager polarisPropertySourceManager + * @return PolarisConfigFilePuller instance + */ + public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, + PolarisPropertySourceManager polarisPropertySourceManager) { + PolarisConfigFilePuller puller = new PolarisConfigFilePuller(); + puller.polarisContextProperties = polarisContextProperties; + puller.configFileService = configFileService; + puller.polarisPropertySourceManager = polarisPropertySourceManager; + return puller; + } +} diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLoader.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLoader.java index 1354708c7..9b0f08550 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLoader.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLoader.java @@ -144,9 +144,9 @@ public class PolarisConfigDataLoader implements ConfigDataLoader flies = new ArrayList<>(); - flies.add(fileName); - configFileGroup.setFiles(flies); + List files = new ArrayList<>(); + files.add(fileName); + configFileGroup.setFiles(files); return configFileGroup; } } diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataMissingEnvironmentPostProcessor.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataMissingEnvironmentPostProcessor.java index b2bf3ef9d..6c946e6c6 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataMissingEnvironmentPostProcessor.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataMissingEnvironmentPostProcessor.java @@ -1,3 +1,20 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package com.tencent.cloud.polaris.config.configdata; import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor; diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataResource.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataResource.java index 0029a5664..04b81a487 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataResource.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataResource.java @@ -1 +1,114 @@ -/* * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. * * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the BSD 3-Clause License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-3-Clause * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package com.tencent.cloud.polaris.config.configdata; import java.util.Objects; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; import com.tencent.cloud.polaris.context.config.PolarisContextProperties; import org.springframework.boot.context.config.ConfigData; import org.springframework.boot.context.config.ConfigDataResource; import org.springframework.boot.context.config.Profiles; /** * A polaris configData resource from which {@link ConfigData} can be loaded. * * @author wlx * @date 2022/7/5 11:13 下午 */ public class PolarisConfigDataResource extends ConfigDataResource { private final PolarisConfigProperties polarisConfigProperties; private final PolarisContextProperties polarisContextProperties; private final Profiles profiles; private final boolean optional; private final String fileName; private final String groupName; private final String serviceName; public PolarisConfigDataResource(PolarisConfigProperties polarisConfigProperties, PolarisContextProperties polarisContextProperties, Profiles profiles, boolean optional, String fileName, String groupName, String serviceName) { this.polarisConfigProperties = polarisConfigProperties; this.polarisContextProperties = polarisContextProperties; this.profiles = profiles; this.optional = optional; this.fileName = fileName; this.groupName = groupName; this.serviceName = serviceName; } public PolarisConfigProperties getPolarisConfigProperties() { return polarisConfigProperties; } public PolarisContextProperties getPolarisContextProperties() { return polarisContextProperties; } public Profiles getProfiles() { return profiles; } public boolean isOptional() { return optional; } public String getFileName() { return fileName; } public String getGroupName() { return groupName; } public String getServiceName() { return serviceName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } PolarisConfigDataResource that = (PolarisConfigDataResource) o; return optional == that.optional && polarisConfigProperties.equals(that.polarisConfigProperties) && polarisContextProperties.equals(that.polarisContextProperties) && profiles.equals(that.profiles) && fileName.equals(that.fileName) && groupName.equals(that.groupName) && serviceName.equals(that.serviceName); } @Override public int hashCode() { return Objects.hash(polarisConfigProperties, polarisContextProperties, profiles, optional, fileName, groupName, serviceName); } } \ No newline at end of file +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.config.configdata; + +import java.util.Objects; + +import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; +import com.tencent.cloud.polaris.context.config.PolarisContextProperties; + +import org.springframework.boot.context.config.ConfigData; +import org.springframework.boot.context.config.ConfigDataResource; +import org.springframework.boot.context.config.Profiles; + +/** + * A polaris configData resource from which {@link ConfigData} can be loaded. + * + * @author wlx + * @date 2022/7/5 11:13 下午 + */ +public class PolarisConfigDataResource extends ConfigDataResource { + + private final PolarisConfigProperties polarisConfigProperties; + + private final PolarisContextProperties polarisContextProperties; + + private final Profiles profiles; + + private final boolean optional; + + private final String fileName; + + private final String groupName; + + private final String serviceName; + + public PolarisConfigDataResource(PolarisConfigProperties polarisConfigProperties, + PolarisContextProperties polarisContextProperties, + Profiles profiles, boolean optional, + String fileName, String groupName, String serviceName) { + this.polarisConfigProperties = polarisConfigProperties; + this.polarisContextProperties = polarisContextProperties; + this.profiles = profiles; + this.optional = optional; + this.fileName = fileName; + this.groupName = groupName; + this.serviceName = serviceName; + } + + public PolarisConfigProperties getPolarisConfigProperties() { + return polarisConfigProperties; + } + + public PolarisContextProperties getPolarisContextProperties() { + return polarisContextProperties; + } + + public Profiles getProfiles() { + return profiles; + } + + public boolean isOptional() { + return optional; + } + + public String getFileName() { + return fileName; + } + + public String getGroupName() { + return groupName; + } + + public String getServiceName() { + return serviceName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PolarisConfigDataResource that = (PolarisConfigDataResource) o; + return optional == that.optional && + polarisConfigProperties.equals(that.polarisConfigProperties) && + polarisContextProperties.equals(that.polarisContextProperties) && + profiles.equals(that.profiles) && + fileName.equals(that.fileName) && + groupName.equals(that.groupName) && + serviceName.equals(that.serviceName); + } + + @Override + public int hashCode() { + return Objects.hash(polarisConfigProperties, polarisContextProperties, profiles, optional, fileName, groupName, serviceName); + } +} diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 75bc4907e..09c3e0f69 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-starter-tencent-polaris-config/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -47,6 +47,12 @@ "type": "java.lang.Boolean", "defaultValue": true, "description": "Whether to enable import-check." + }, + { + "name": "spring.cloud.polaris.config.preference", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "Whether to preferentially load the remote configuration." } ] }