) getSource();
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessor.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessor.java
deleted file mode 100644
index 9064667c0..000000000
--- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessor.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.spring.property;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.collect.LinkedListMultimap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.PropertyValue;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.TypedStringValue;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
-import org.springframework.lang.NonNull;
-
-/**
- * To process xml config placeholders, e.g.
- *
- *
- * <bean class="com.demo.bean.XmlBean">
- * <property name="timeout" value="${timeout:200}"/>
- * <property name="batch" value="${batch:100}"/>
- * </bean>
- *
- *
- * This source file was originally from:
- *
- * SpringValueDefinitionProcessor
- *
- * @author weihubeats 2022-7-10
- */
-public class SpringValueDefinitionProcessor implements BeanDefinitionRegistryPostProcessor {
- private static final Map> beanName2SpringValueDefinitions =
- Maps.newConcurrentMap();
- private static final Set PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES = Sets.newConcurrentHashSet();
-
- private final PlaceholderHelper placeholderHelper;
-
- private final PolarisConfigProperties polarisConfigProperties;
-
- public SpringValueDefinitionProcessor(PlaceholderHelper placeholderHelper, PolarisConfigProperties polarisConfigProperties) {
- this.polarisConfigProperties = polarisConfigProperties;
- this.placeholderHelper = placeholderHelper;
- }
-
- public static Multimap getBeanName2SpringValueDefinitions(BeanDefinitionRegistry registry) {
- Multimap springValueDefinitions = beanName2SpringValueDefinitions.get(registry);
- if (springValueDefinitions == null) {
- springValueDefinitions = LinkedListMultimap.create();
- }
-
- return springValueDefinitions;
- }
-
- @Override
- public void postProcessBeanDefinitionRegistry(@NonNull BeanDefinitionRegistry registry) throws BeansException {
- if (polarisConfigProperties.isAutoRefresh()) {
- processPropertyValues(registry);
- }
- }
-
- @Override
- public void postProcessBeanFactory(@NonNull ConfigurableListableBeanFactory beanFactory) throws BeansException {
-
- }
-
- private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
- if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
- // already initialized
- return;
- }
-
- if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
- beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.create());
- }
-
- Multimap springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);
-
- String[] beanNames = beanRegistry.getBeanDefinitionNames();
- for (String beanName : beanNames) {
- BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
- MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
- List propertyValues = mutablePropertyValues.getPropertyValueList();
- for (PropertyValue propertyValue : propertyValues) {
- Object value = propertyValue.getValue();
- if (!(value instanceof TypedStringValue)) {
- continue;
- }
- String placeholder = ((TypedStringValue) value).getValue();
- Set keys = placeholderHelper.extractPlaceholderKeys(placeholder);
-
- if (keys.isEmpty()) {
- continue;
- }
-
- for (String key : keys) {
- springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
- }
- }
- }
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
index 99f1b9b14..b4bd33afd 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
@@ -27,6 +27,7 @@ import java.util.Optional;
import com.tencent.cloud.polaris.config.PolarisConfigBootstrapAutoConfiguration;
import com.tencent.cloud.polaris.config.enums.RefreshType;
+import com.tencent.cloud.polaris.config.spring.property.Person;
import com.tencent.cloud.polaris.config.spring.property.SpringValue;
import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry;
import com.tencent.polaris.api.utils.CollectionUtils;
@@ -43,6 +44,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
import org.springframework.stereotype.Component;
/**
@@ -138,6 +140,53 @@ public class SpringValueProcessorTest {
});
}
+ @Test
+ public void xmlBeamDefinitionTest() {
+ ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(PolarisConfigBootstrapAutoConfiguration.class))
+ .withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
+ .withConfiguration(AutoConfigurations.of(XMLBeamDefinitionTest.class))
+ .withConfiguration(AutoConfigurations.of(PolarisConfigAutoConfiguration.class))
+ .withPropertyValues("spring.application.name=" + "conditionalOnConfigReflectEnabledTest")
+ .withPropertyValues("spring.cloud.polaris.address=grpc://127.0.0.1:10081")
+ .withPropertyValues("spring.cloud.polaris.config.refresh-type=" + RefreshType.REFLECT)
+ .withPropertyValues("spring.cloud.polaris.config.enabled=true")
+ .withPropertyValues("name=test");
+ contextRunner.run(context -> {
+ Person person = context.getBean(Person.class);
+
+ SpringValueRegistry springValueRegistry = context.getBean(SpringValueRegistry.class);
+ BeanFactory beanFactory = person.getBeanFactory();
+ Collection name = springValueRegistry.get(beanFactory, "name");
+ Assert.assertFalse(CollectionUtils.isEmpty(name));
+ Optional nameSpringValueOptional = name.stream().findAny();
+ Assert.assertTrue(nameSpringValueOptional.isPresent());
+
+ SpringValue nameSpringValue = nameSpringValueOptional.get();
+ Method method = nameSpringValue.getMethodParameter().getMethod();
+ Assert.assertTrue(Objects.nonNull(method));
+ Assert.assertEquals("setName", method.getName());
+ Assert.assertEquals("${name:test}", nameSpringValue.getPlaceholder());
+ Assert.assertFalse(nameSpringValue.isField());
+ Assert.assertEquals(String.class, nameSpringValue.getTargetType());
+
+
+ Collection age = springValueRegistry.get(beanFactory, "age");
+ Assert.assertFalse(CollectionUtils.isEmpty(age));
+ Optional ageSpringValueOptional = age.stream().findAny();
+ Assert.assertTrue(ageSpringValueOptional.isPresent());
+
+ SpringValue ageSpringValue = ageSpringValueOptional.get();
+ Method method1 = ageSpringValue.getMethodParameter().getMethod();
+ Assert.assertTrue(Objects.nonNull(method1));
+ Assert.assertEquals("setAge", method1.getName());
+ Assert.assertEquals("${age:10}", ageSpringValue.getPlaceholder());
+ Assert.assertFalse(ageSpringValue.isField());
+ Assert.assertEquals(String.class, ageSpringValue.getTargetType());
+ });
+
+ }
+
@Configuration
@EnableAutoConfiguration
static class PolarisConfigAutoConfiguration {
@@ -173,4 +222,9 @@ public class SpringValueProcessorTest {
ValueTest.name = name;
}
}
+
+ @Configuration
+ @ImportResource("classpath:bean.xml")
+ static class XMLBeamDefinitionTest {
+ }
}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/event/ConfigChangeSpringEventTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/event/ConfigChangeSpringEventTest.java
new file mode 100644
index 000000000..2e44c476e
--- /dev/null
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/event/ConfigChangeSpringEventTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.spring.event;
+
+import java.util.HashMap;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.tencent.polaris.configuration.api.core.ChangeType;
+import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Configuration;
+
+
+/**
+ * Test for {@link ConfigChangeSpringEvent}.
+ *
+ * @author derek.yi 2022-10-16
+ */
+public class ConfigChangeSpringEventTest {
+
+ private static CountDownLatch countDownLatch = new CountDownLatch(1);
+
+ private static AtomicInteger receiveEventTimes = new AtomicInteger();
+
+ @Test
+ public void testPublishConfigChangeSpringEvent() {
+ ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(ConfigChangeSpringEventListener.class));
+ contextRunner.run(context -> {
+ HashMap changeMap = new HashMap<>();
+ changeMap.put("key", new ConfigPropertyChangeInfo("key", null, "value", ChangeType.ADDED));
+ context.publishEvent(new ConfigChangeSpringEvent(changeMap));
+ countDownLatch.await(5, TimeUnit.SECONDS);
+ Assert.assertEquals(1, receiveEventTimes.get());
+ });
+ }
+
+ @Configuration
+ static class ConfigChangeSpringEventListener implements ApplicationListener {
+
+ @Override
+ public void onApplicationEvent(ConfigChangeSpringEvent event) {
+ Set changedKeys = event.changedKeys();
+ Assert.assertEquals(1, changedKeys.size());
+ Assert.assertTrue(event.isChanged("key"));
+ ConfigPropertyChangeInfo changeInfo = event.getChange("key");
+ Assert.assertNotNull(changeInfo);
+ Assert.assertEquals("key", changeInfo.getPropertyName());
+ Assert.assertEquals("value", changeInfo.getNewValue());
+ Assert.assertEquals(ChangeType.ADDED, changeInfo.getChangeType());
+
+ receiveEventTimes.incrementAndGet();
+ countDownLatch.countDown();
+ }
+ }
+}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessorTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessorTest.java
deleted file mode 100644
index c82980a41..000000000
--- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/property/SpringValueDefinitionProcessorTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.spring.property;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Optional;
-
-import com.tencent.polaris.api.utils.CollectionUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-/**
- * Test for {@link SpringValueDefinitionProcessor}.
- *
- * @author lingxiao.wlx
- */
-public class SpringValueDefinitionProcessorTest {
-
- @Test
- public void springValueDefinitionProcessorTest() {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
- Person person = context.getBean(Person.class);
-
- SpringValueRegistry springValueRegistry = context.getBean(SpringValueRegistry.class);
-
- BeanFactory beanFactory = person.getBeanFactory();
- Collection name = springValueRegistry.get(beanFactory, "name");
- Assert.assertFalse(CollectionUtils.isEmpty(name));
- Optional nameSpringValueOptional = name.stream().findAny();
- Assert.assertTrue(nameSpringValueOptional.isPresent());
-
- SpringValue nameSpringValue = nameSpringValueOptional.get();
- Method method = nameSpringValue.getMethodParameter().getMethod();
- Assert.assertTrue(Objects.nonNull(method));
- Assert.assertEquals("setName", method.getName());
- Assert.assertEquals("${name:test}", nameSpringValue.getPlaceholder());
- Assert.assertFalse(nameSpringValue.isField());
- Assert.assertEquals(String.class, nameSpringValue.getTargetType());
-
-
- Collection age = springValueRegistry.get(beanFactory, "age");
- Assert.assertFalse(CollectionUtils.isEmpty(age));
- Optional ageSpringValueOptional = age.stream().findAny();
- Assert.assertTrue(ageSpringValueOptional.isPresent());
-
- SpringValue ageSpringValue = ageSpringValueOptional.get();
- Method method1 = ageSpringValue.getMethodParameter().getMethod();
- Assert.assertTrue(Objects.nonNull(method1));
- Assert.assertEquals("setAge", method1.getName());
- Assert.assertEquals("${age:10}", ageSpringValue.getPlaceholder());
- Assert.assertFalse(ageSpringValue.isField());
- Assert.assertEquals(String.class, ageSpringValue.getTargetType());
- }
-}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/resources/bean.xml b/spring-cloud-starter-tencent-polaris-config/src/test/resources/bean.xml
index e60613a5a..e6484c467 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/test/resources/bean.xml
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/resources/bean.xml
@@ -11,28 +11,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml
index 7e2425a9a..4b7214f9f 100644
--- a/spring-cloud-tencent-dependencies/pom.xml
+++ b/spring-cloud-tencent-dependencies/pom.xml
@@ -70,7 +70,7 @@
- 1.8.0-2021.0.3-SNAPSHOT
+ 1.9.0-2021.0.3-SNAPSHOT
1.9.1
diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/pom.xml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/pom.xml
index e79635589..69bf28210 100644
--- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/pom.xml
+++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/pom.xml
@@ -34,6 +34,11 @@
spring-cloud-tencent-gateway-plugin
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-metadata-transfer
+
+
com.tencent.cloud
spring-cloud-tencent-featureenv-plugin