From bd4b39297eea4b3cedf9bf1d10916a375dfcc4b1 Mon Sep 17 00:00:00 2001 From: wulingxiao <1251605638@qqcom> Date: Sat, 16 Jul 2022 13:15:16 +0800 Subject: [PATCH] feature:support spring cloud configData --- .../adapter/PolarisConfigFileLocator.java | 2 -- .../config/adapter/PolarisConfigFilePuller.java | 2 +- .../configdata/PolarisConfigDataLoader.java | 17 +++++++++++++++++ .../PolarisConfigDataLocationResolver.java | 17 +++++++++++++++++ .../configdata/PolarisConfigDataResource.java | 2 +- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFileLocator.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFileLocator.java index 93b3733af..7479d761a 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFileLocator.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFileLocator.java @@ -23,8 +23,6 @@ import com.tencent.cloud.polaris.config.config.ConfigFileGroup; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; import com.tencent.cloud.polaris.context.config.PolarisContextProperties; import com.tencent.polaris.configuration.api.core.ConfigFileService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.core.annotation.Order; 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 a4399089c..078e53db5 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 @@ -package com.tencent.cloud.polaris.config.adapter; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import com.google.common.collect.Lists; import com.tencent.cloud.polaris.config.config.ConfigFileGroup; 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.boot.context.config.Profiles; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** * PolarisConfigFilePuller pull configFile from Polaris. * * @author wlx */ public class PolarisConfigFilePuller { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigFileLocator.class); private final PolarisContextProperties polarisContextProperties; private final ConfigFileService configFileService; private final PolarisPropertySourceManager polarisPropertySourceManager; private Environment environment; public PolarisConfigFilePuller(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager, Environment environment) { this.polarisContextProperties = polarisContextProperties; this.configFileService = configFileService; this.polarisPropertySourceManager = polarisPropertySourceManager; this.environment = environment; } public PolarisConfigFilePuller(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager) { this.polarisContextProperties = polarisContextProperties; this.configFileService = configFileService; this.polarisPropertySourceManager = polarisPropertySourceManager; } public void initInternalConfigFiles(CompositePropertySource compositePropertySource) { List internalConfigFiles = getInternalConfigFiles(); 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); } } public void initInternalConfigFiles(CompositePropertySource compositePropertySource, Profiles profiles, String serviceName) { List internalConfigFiles = getInternalConfigFiles(profiles, 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); } } public void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource, List configFileGroups) { configFileGroups.forEach( configFileGroup -> initCustomPolarisConfigFile(compositePropertySource, 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 namespace = polarisContextProperties.getNamespace(); String serviceName = polarisContextProperties.getService(); if (Objects.isNull(this.environment)) { return Lists.newArrayList(); } if (!StringUtils.hasText(serviceName)) { serviceName = environment.getProperty("spring.application.name"); } // priority: application-${profile} > application > boostrap-${profile} > boostrap String[] activeProfiles = environment.getActiveProfiles(); return getInternalConfigFiles(activeProfiles, namespace, serviceName); } private List getInternalConfigFiles(Profiles profiles, String serviceName) { String namespace = polarisContextProperties.getNamespace(); if (StringUtils.hasText(polarisContextProperties.getService())) { serviceName = polarisContextProperties.getService(); } // priority: application-${profile} > application > boostrap-${profile} > boostrap List active = profiles.getActive(); String[] activeProfiles = active.toArray(new String[]{}); 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; } } \ 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.Objects; import java.util.concurrent.ConcurrentHashMap; import com.google.common.collect.Lists; import com.tencent.cloud.polaris.config.config.ConfigFileGroup; 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.boot.context.config.Profiles; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; /** * PolarisConfigFilePuller pull configFile from Polaris. * * @author wlx */ public class PolarisConfigFilePuller { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigFileLocator.class); private final PolarisContextProperties polarisContextProperties; private final ConfigFileService configFileService; private final PolarisPropertySourceManager polarisPropertySourceManager; private Environment environment; public PolarisConfigFilePuller(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager, Environment environment) { this.polarisContextProperties = polarisContextProperties; this.configFileService = configFileService; this.polarisPropertySourceManager = polarisPropertySourceManager; this.environment = environment; } public PolarisConfigFilePuller(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager) { this.polarisContextProperties = polarisContextProperties; this.configFileService = configFileService; this.polarisPropertySourceManager = polarisPropertySourceManager; } public void initInternalConfigFiles(CompositePropertySource compositePropertySource) { List internalConfigFiles = getInternalConfigFiles(); 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); } } public void initInternalConfigFiles(CompositePropertySource compositePropertySource, Profiles profiles, String serviceName) { List internalConfigFiles = getInternalConfigFiles(profiles, 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); } } public void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource, List configFileGroups) { configFileGroups.forEach( configFileGroup -> initCustomPolarisConfigFile(compositePropertySource, 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 namespace = polarisContextProperties.getNamespace(); String serviceName = polarisContextProperties.getService(); if (Objects.isNull(this.environment)) { return Lists.newArrayList(); } if (!StringUtils.hasText(serviceName)) { serviceName = environment.getProperty("spring.application.name"); } // priority: application-${profile} > application > boostrap-${profile} > boostrap String[] activeProfiles = environment.getActiveProfiles(); return getInternalConfigFiles(activeProfiles, namespace, serviceName); } private List getInternalConfigFiles(Profiles profiles, String serviceName) { String namespace = polarisContextProperties.getNamespace(); if (StringUtils.hasText(polarisContextProperties.getService())) { serviceName = polarisContextProperties.getService(); } // priority: application-${profile} > application > boostrap-${profile} > boostrap List active = profiles.getActive(); String[] activeProfiles = active.toArray(new String[]{}); 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; } } \ No newline at end of file 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 5b0ad0145..627f675ca 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 @@ -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 java.util.ArrayList; diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLocationResolver.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLocationResolver.java index 302719e80..81ec971ff 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLocationResolver.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/configdata/PolarisConfigDataLocationResolver.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 java.util.ArrayList; 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 64fc62619..0029a5664 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 @@ -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); } } \ No newline at end of file