From 2e9fdd1c75daec233a900eed584d3c2048f17d5c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:11:56 +0800 Subject: [PATCH 01/51] Update pom.xml --- microsphere-spring-boot-actuator/pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/microsphere-spring-boot-actuator/pom.xml b/microsphere-spring-boot-actuator/pom.xml index 0d65ebf..ca4da0f 100644 --- a/microsphere-spring-boot-actuator/pom.xml +++ b/microsphere-spring-boot-actuator/pom.xml @@ -27,6 +27,13 @@ ${revision} + + + org.jolokia + jolokia-core + ${jolokia.version} + + org.springframework.boot @@ -46,6 +53,12 @@ true + + org.springframework.boot + spring-boot-configuration-processor + true + + org.springframework.boot From f92879e5be39c26df67fb81843cb96a96c4d8020 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:12:02 +0800 Subject: [PATCH 02/51] Update pom.xml --- microsphere-spring-boot-parent/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/microsphere-spring-boot-parent/pom.xml b/microsphere-spring-boot-parent/pom.xml index 548a5fc..74e13a0 100644 --- a/microsphere-spring-boot-parent/pom.xml +++ b/microsphere-spring-boot-parent/pom.xml @@ -20,6 +20,7 @@ 2.0.0-SNAPSHOT + 1.7.2 From da36be1f39df5f12db048de054fb0b738a080975 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:12:04 +0800 Subject: [PATCH 03/51] Create logback.xml --- .../src/test/resources/logback.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/test/resources/logback.xml diff --git a/microsphere-core-spring-boot-starter/src/test/resources/logback.xml b/microsphere-core-spring-boot-starter/src/test/resources/logback.xml new file mode 100644 index 0000000..15fd317 --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/test/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + + ${ENCODER_PATTERN} + + + + + + + + + + + \ No newline at end of file From c0167d97b8a20e4e48b0484adbc756c78e0ed638 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:12:07 +0800 Subject: [PATCH 04/51] Create ConfigurationMetadataReader.java --- .../metadata/ConfigurationMetadataReader.java | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java new file mode 100644 index 0000000..e7cd17f --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import io.microsphere.logging.Logger; +import io.microsphere.logging.LoggerFactory; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.lang.NonNull; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +import static io.microsphere.text.FormatUtils.format; +import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; +import static io.microsphere.util.StringUtils.replace; +import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX; + +/** + * The Reader of {@link ConfigurationMetadata} + * + * @author Mercy + * @see ConfigurationMetadata + * @since 1.0.0 + */ +public class ConfigurationMetadataReader { + + private static final Logger logger = LoggerFactory.getLogger(ConfigurationMetadataReader.class); + + private static final String METADATA_RESOURCE_NAME = "spring-configuration-metadata.json"; + + private static final String ADDITIONAL_METADATA_RESOURCE_NAME = "additional-spring-configuration-metadata.json"; + + private static final String META_INFO_PATH = "/META-INF/"; + + private static final String METADATA_RESOURCE_PATH = META_INFO_PATH + METADATA_RESOURCE_NAME; + + private static final String ADDITIONAL_METADATA_RESOURCE_PATH = META_INFO_PATH + ADDITIONAL_METADATA_RESOURCE_NAME; + + public static final String METADATA_RESOURCE_PATTERN_PATH = CLASSPATH_ALL_URL_PREFIX + METADATA_RESOURCE_PATH; + + public static final String ADDITIONAL_METADATA_RESOURCE_PATTERN_PATH = CLASSPATH_ALL_URL_PREFIX + ADDITIONAL_METADATA_RESOURCE_PATH; + + private final ResourcePatternResolver resourcePatternResolver; + + public ConfigurationMetadataReader() { + this(getDefaultClassLoader()); + } + + public ConfigurationMetadataReader(ClassLoader classLoader) { + this.resourcePatternResolver = new PathMatchingResourcePatternResolver(classLoader); + } + + public ConfigurationMetadata read() { + ConfigurationMetadata configurationMetadata = new ConfigurationMetadata(); + Resource[] metadataResources = getMetadataResources(); + int metadataResourcesSize = metadataResources.length; + Set processedAdditionalMetadataResources = new HashSet<>(metadataResourcesSize); + for (int i = 0; i < metadataResourcesSize; i++) { + Resource resource = metadataResources[i]; + processConfigurationMetadata(configurationMetadata, resource, processedAdditionalMetadataResources); + } + Resource[] additionalMetadataResources = getAdditionalMetadataResources(); + for (Resource additionalMetadataResource : additionalMetadataResources) { + if (processedAdditionalMetadataResources.remove(additionalMetadataResource)) { + continue; + } + processConfigurationMetadata(configurationMetadata, additionalMetadataResource); + } + return configurationMetadata; + } + + private void processConfigurationMetadata(ConfigurationMetadata configurationMetadata, Resource metadataResource, + Set processedAdditionalMetadataResources) { + processConfigurationMetadata(configurationMetadata, metadataResource); + tryProcessAdditionalMetadataResource(configurationMetadata, metadataResource, processedAdditionalMetadataResources); + } + + private void tryProcessAdditionalMetadataResource(ConfigurationMetadata configurationMetadata, Resource metadataResource, + Set processedAdditionalMetadataResources) { + try { + URI uri = metadataResource.getURI(); + String metadataResourcePath = uri.toString(); + String additionalMetadataResourcePath = replace(metadataResourcePath, METADATA_RESOURCE_NAME, ADDITIONAL_METADATA_RESOURCE_NAME); + Resource additionalMetadataResource = this.resourcePatternResolver.getResource(additionalMetadataResourcePath); + if (additionalMetadataResource.exists()) { + processConfigurationMetadata(configurationMetadata, additionalMetadataResource); + processedAdditionalMetadataResources.add(additionalMetadataResource); + } else { + if (logger.isDebugEnabled()) { + logger.debug("The Additional Configuration Metadata resource[{}] can't be found", additionalMetadataResource); + } + } + } catch (IOException e) { + String message = format("The Additional Configuration Metadata resource[{}] can't be open", metadataResource); + throw new RuntimeException(message, e); + } + } + + private void processConfigurationMetadata(ConfigurationMetadata configurationMetadata, Resource metadataResource) { + ConfigurationMetadata metadata = loadConfigurationMetadata(metadataResource); + configurationMetadata.merge(metadata); + } + + private ConfigurationMetadata loadConfigurationMetadata(Resource metadataResource) { + JsonMarshaller jsonMarshaller = new JsonMarshaller(); + final ConfigurationMetadata configurationMetadata; + try (InputStream inputStream = metadataResource.getInputStream()) { + configurationMetadata = jsonMarshaller.read(inputStream); + if (logger.isDebugEnabled()) { + logger.debug("Loaded the Configuration Metadata resource[{}] : {}", metadataResource, configurationMetadata); + } + } catch (Throwable e) { + String message = format("The Configuration Metadata resource[{}] can't be loaded", metadataResource); + throw new RuntimeException(message, e); + } + return configurationMetadata; + } + + @NonNull + private Resource[] getMetadataResources() { + return getResources(METADATA_RESOURCE_PATTERN_PATH); + } + + @NonNull + private Resource[] getAdditionalMetadataResources() { + return getResources(ADDITIONAL_METADATA_RESOURCE_PATTERN_PATH); + } + + @NonNull + private Resource[] getResources(String metadataResourcePatternPath) { + Resource[] metadataResources = null; + try { + metadataResources = this.resourcePatternResolver.getResources(metadataResourcePatternPath); + } catch (IOException e) { + String message = format("The Configuration Metadata resources[pattern : {}] can't be read", metadataResourcePatternPath); + throw new RuntimeException(message, e); + } + return metadataResources; + } +} From 644d6e91afc67681b9700be5f4a61d9185ad0154 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:12:09 +0800 Subject: [PATCH 05/51] Create ConfigurationMetadataReaderTest.java --- .../ConfigurationMetadataReaderTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java new file mode 100644 index 0000000..b94b9ae --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * {@link ConfigurationMetadataReader} Test + * + * @author Mercy + * @see ConfigurationMetadataReader + * @since 1.0.0 + */ +public class ConfigurationMetadataReaderTest { + + @Test + public void testRead() throws Throwable { + ConfigurationMetadataReader reader = new ConfigurationMetadataReader(); + ConfigurationMetadata metadata = reader.read(); + assertNotNull(metadata); + } +} From a113f4520596b90c888e7d3bf813b9329ecb4e20 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:18:10 +0800 Subject: [PATCH 06/51] Update ConfigurationMetadataReader.java --- .../metadata/ConfigurationMetadataReader.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java index e7cd17f..b648799 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java @@ -47,15 +47,15 @@ public class ConfigurationMetadataReader { private static final Logger logger = LoggerFactory.getLogger(ConfigurationMetadataReader.class); - private static final String METADATA_RESOURCE_NAME = "spring-configuration-metadata.json"; + public static final String METADATA_RESOURCE_NAME = "spring-configuration-metadata.json"; - private static final String ADDITIONAL_METADATA_RESOURCE_NAME = "additional-spring-configuration-metadata.json"; + public static final String ADDITIONAL_METADATA_RESOURCE_NAME = "additional-spring-configuration-metadata.json"; private static final String META_INFO_PATH = "/META-INF/"; - private static final String METADATA_RESOURCE_PATH = META_INFO_PATH + METADATA_RESOURCE_NAME; + public static final String METADATA_RESOURCE_PATH = META_INFO_PATH + METADATA_RESOURCE_NAME; - private static final String ADDITIONAL_METADATA_RESOURCE_PATH = META_INFO_PATH + ADDITIONAL_METADATA_RESOURCE_NAME; + public static final String ADDITIONAL_METADATA_RESOURCE_PATH = META_INFO_PATH + ADDITIONAL_METADATA_RESOURCE_NAME; public static final String METADATA_RESOURCE_PATTERN_PATH = CLASSPATH_ALL_URL_PREFIX + METADATA_RESOURCE_PATH; From edaa1e7e1df37782e36acf834f10db6b0a888bd7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:27:49 +0800 Subject: [PATCH 07/51] Create ConfigurationMetadataEndpoint.java --- .../ConfigurationMetadataEndpoint.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java new file mode 100644 index 0000000..b382ab4 --- /dev/null +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.actuate.endpoint; + +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; + +/** + * {@link ConfigurationMetadata} {@link Endpoint} + * + * @author Mercy + * @see ConfigurationMetadata + * @since 1.0.0 + */ +@Endpoint(id = "configMetadata") +public class ConfigurationMetadataEndpoint { + + private final ConfigurationMetadataReader configurationMetadataReader; + + public ConfigurationMetadataEndpoint(ClassLoader classLoader) { + this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); + } + + @ReadOperation + public ConfigurationMetadata getConfigurationMetadata() { + return this.configurationMetadataReader.read(); + } + +} From ad8232e7df8c53897ac9880bdae43c4a927bfa29 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:27:53 +0800 Subject: [PATCH 08/51] Update endpoints.properties --- .../resources/META-INF/config/default/endpoints.properties | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-spring-boot-actuator/src/main/resources/META-INF/config/default/endpoints.properties b/microsphere-spring-boot-actuator/src/main/resources/META-INF/config/default/endpoints.properties index 091964e..8aa300d 100644 --- a/microsphere-spring-boot-actuator/src/main/resources/META-INF/config/default/endpoints.properties +++ b/microsphere-spring-boot-actuator/src/main/resources/META-INF/config/default/endpoints.properties @@ -75,6 +75,12 @@ management.endpoint.artifacts.enabled = true management.endpoints.web.path-mapping.artifacts = microsphere/artifacts management.endpoint.artifacts.cache.time-to-live = ${microsphere.cache.long-long-time-to-live} +### WebEndpoints Endpoint management.endpoint.webEndpoints.enabled = true management.endpoints.web.path-mapping.webEndpoints = microsphere/web/endpoints management.endpoint.webEndpoints.cache.time-to-live = ${microsphere.cache.short-time-to-live} + +### ConfigurationMetadata Endpoint +management.endpoint.configMetadata.enabled = true +management.endpoints.web.path-mapping.configMetadata = microsphere/config/metadata +management.endpoint.configMetadata.cache.time-to-live = ${microsphere.cache.long-long-time-to-live} \ No newline at end of file From 7388dca97b1dfbc0db73941b8a34b4f4b0da980e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:27:57 +0800 Subject: [PATCH 09/51] Update ActuatorEndpointsAutoConfiguration.java --- .../ActuatorEndpointsAutoConfiguration.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index 464a927..8f120f9 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -17,6 +17,7 @@ package io.microsphere.spring.boot.actuate.autoconfigure; import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; +import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; @@ -57,6 +58,14 @@ public WebEndpoints webEndpoints(WebEndpointsSupplier webEndpointsSupplier) { return new WebEndpoints(webEndpointsSupplier); } + @Bean + @ConditionalOnClass(name = "org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata") + @ConditionalOnMissingBean + @ConditionalOnAvailableEndpoint + public ConfigurationMetadataEndpoint configurationMetadataEndpoint() { + return new ConfigurationMetadataEndpoint(classLoader); + } + @Override public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; From 5f8c1fbb8b7df3412eda5c0755e2980f6b6b1c12 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 18:28:00 +0800 Subject: [PATCH 10/51] Update ActuatorEndpointsAutoConfigurationTest.java --- .../ActuatorEndpointsAutoConfigurationTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java index 8c8b1cd..a48b036 100644 --- a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java +++ b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java @@ -1,12 +1,14 @@ package io.microsphere.spring.boot.actuate.autoconfigure; import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; +import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.PropertySource; @@ -28,7 +30,7 @@ }) @PropertySource(value = "classpath:META-INF/config/default/endpoints.properties") @EnableAutoConfiguration -class ActuatorEndpointsAutoConfigurationTest { +public class ActuatorEndpointsAutoConfigurationTest { @Autowired private ArtifactsEndpoint artifactsEndpoint; @@ -36,6 +38,9 @@ class ActuatorEndpointsAutoConfigurationTest { @Autowired private WebEndpoints webEndpoints; + @Autowired + private ConfigurationMetadataEndpoint configurationMetadataEndpoint; + @Test void testArtifactsEndpoint() { assertFalse(artifactsEndpoint.getArtifactMetaInfoList().isEmpty()); @@ -47,6 +52,12 @@ public void testInvokeReadOperations() { assertFalse(aggregatedResults.isEmpty()); } + @Test + public void testGetConfigurationMetadata() { + ConfigurationMetadata configurationMetadata = configurationMetadataEndpoint.getConfigurationMetadata(); + assertFalse(configurationMetadata.getItems().isEmpty()); + } + public static void main(String[] args) { new SpringApplicationBuilder(ActuatorEndpointsAutoConfigurationTest.class) .web(WebApplicationType.SERVLET) From b0bab74c77bfde18d48e55a84cff81f02542feff Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:23:25 +0800 Subject: [PATCH 11/51] Create ConditionalOnConfigurationProcessorPresent.java --- ...tionalOnConfigurationProcessorPresent.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/condition/ConditionalOnConfigurationProcessorPresent.java diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/condition/ConditionalOnConfigurationProcessorPresent.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/condition/ConditionalOnConfigurationProcessorPresent.java new file mode 100644 index 0000000..c45d278 --- /dev/null +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/condition/ConditionalOnConfigurationProcessorPresent.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.actuate.condition; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Conditional; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * {@link Conditional @Conditional} that checks whether the artifact "org.springframework.boot:spring-boot-configuration-processor" + * is present + * + * @author Mercy + * @see Conditional + * @since 1.0.0 + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@ConditionalOnClass(name = "org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata") +public @interface ConditionalOnConfigurationProcessorPresent { +} From 9981dddbf52fd9588a7cbb995f884cf4aec11484 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:23:33 +0800 Subject: [PATCH 12/51] Update ConfigurationMetadataEndpoint.java --- .../boot/actuate/endpoint/ConfigurationMetadataEndpoint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java index b382ab4..956e2b1 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java @@ -22,7 +22,8 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; /** - * {@link ConfigurationMetadata} {@link Endpoint} + * {@link Endpoint @Endpoint} to expose the {@link ConfigurationMetadata Configuration Metadata} that was generated by + * "org.springframework.boot:spring-boot-configuration-processor" * * @author Mercy * @see ConfigurationMetadata @@ -41,5 +42,4 @@ public ConfigurationMetadataEndpoint(ClassLoader classLoader) { public ConfigurationMetadata getConfigurationMetadata() { return this.configurationMetadataReader.read(); } - } From 02a2ba37ebe400961edba02c17b56d6a6212fb48 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:23:36 +0800 Subject: [PATCH 13/51] Update ActuatorEndpointsAutoConfiguration.java --- .../ActuatorEndpointsAutoConfiguration.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index 8f120f9..f2a343a 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -16,6 +16,7 @@ */ package io.microsphere.spring.boot.actuate.autoconfigure; +import io.microsphere.spring.boot.actuate.condition.ConditionalOnConfigurationProcessorPresent; import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; @@ -28,6 +29,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; /** * Actuator {@link Endpoint @Endpoint} Auto-Configuration class @@ -39,6 +41,7 @@ @ConditionalOnClass(name = { "org.springframework.boot.actuate.endpoint.annotation.Endpoint" }) +@Import(value = {ActuatorEndpointsAutoConfiguration.ConfigurationProcessorConfiguration.class}) public class ActuatorEndpointsAutoConfiguration implements BeanClassLoaderAware { private ClassLoader classLoader; @@ -58,12 +61,22 @@ public WebEndpoints webEndpoints(WebEndpointsSupplier webEndpointsSupplier) { return new WebEndpoints(webEndpointsSupplier); } - @Bean - @ConditionalOnClass(name = "org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata") - @ConditionalOnMissingBean - @ConditionalOnAvailableEndpoint - public ConfigurationMetadataEndpoint configurationMetadataEndpoint() { - return new ConfigurationMetadataEndpoint(classLoader); + @ConditionalOnConfigurationProcessorPresent + static class ConfigurationProcessorConfiguration implements BeanClassLoaderAware { + + private ClassLoader classLoader; + + @Bean + @ConditionalOnMissingBean + @ConditionalOnAvailableEndpoint + public ConfigurationMetadataEndpoint configurationMetadataEndpoint() { + return new ConfigurationMetadataEndpoint(classLoader); + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } } @Override From 9d2017a38cdd519a95e8a332b22e054658a40369 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:28:19 +0800 Subject: [PATCH 14/51] Create ConfigurationPropertiesEndpoint.java --- .../ConfigurationPropertiesEndpoint.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java new file mode 100644 index 0000000..7c4afd3 --- /dev/null +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.actuate.endpoint; + +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; + +/** + * {@link Endpoint @Endpoint} to expose the configuration properties + * + * @author Mercy + * @see ConfigurationMetadata + * @since 1.0.0 + */ +@Endpoint(id = "configProperties") +public class ConfigurationPropertiesEndpoint { + + private final ConfigurationMetadataReader configurationMetadataReader; + + public ConfigurationPropertiesEndpoint(ClassLoader classLoader) { + this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); + } + + @ReadOperation + public ConfigurationMetadata getConfigurationMetadata() { + return this.configurationMetadataReader.read(); + } +} From 4b6f0b016a2be88a2b67734368fa00a7a0f945f6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:28:38 +0800 Subject: [PATCH 15/51] Update ConfigurationMetadataEndpoint.java --- .../boot/actuate/endpoint/ConfigurationMetadataEndpoint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java index 956e2b1..a2ac267 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java @@ -34,8 +34,8 @@ public class ConfigurationMetadataEndpoint { private final ConfigurationMetadataReader configurationMetadataReader; - public ConfigurationMetadataEndpoint(ClassLoader classLoader) { - this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); + public ConfigurationMetadataEndpoint(ConfigurationMetadataReader configurationMetadataReader) { + this.configurationMetadataReader = configurationMetadataReader; } @ReadOperation From 7b74c66496ee9857afaf8c2586574eb7edd3b9b2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 15 Nov 2024 19:28:41 +0800 Subject: [PATCH 16/51] Update ActuatorEndpointsAutoConfiguration.java --- .../ActuatorEndpointsAutoConfiguration.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index f2a343a..a4c9b55 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -20,6 +20,7 @@ import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -66,11 +67,17 @@ static class ConfigurationProcessorConfiguration implements BeanClassLoaderAware private ClassLoader classLoader; + @Bean + @ConditionalOnMissingBean + public ConfigurationMetadataReader configurationMetadataReader() { + return new ConfigurationMetadataReader(this.classLoader); + } + @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint - public ConfigurationMetadataEndpoint configurationMetadataEndpoint() { - return new ConfigurationMetadataEndpoint(classLoader); + public ConfigurationMetadataEndpoint configurationMetadataEndpoint(ConfigurationMetadataReader configurationMetadataReader) { + return new ConfigurationMetadataEndpoint(configurationMetadataReader); } @Override From 2d633050efa0b852b581b4fc758a78254878bc22 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:29:33 +0800 Subject: [PATCH 17/51] Create ConfigurationMetadataRepository.java --- .../ConfigurationMetadataRepository.java | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java new file mode 100644 index 0000000..1799ffc --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.configurationprocessor.metadata.ItemHint; +import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static java.util.Collections.emptyList; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.GROUP; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.PROPERTY; + +/** + * The Repository for {@link ConfigurationMetadata} + * + * @author Mercy + * @see ConfigurationMetadata + * @see ConfigurationMetadataReader + * @since 1.0.0 + */ +public class ConfigurationMetadataRepository implements BeanClassLoaderAware, CommandLineRunner { + + private ConfigurationMetadataReader configurationMetadataReader; + + private Map namedGroupItems; + + private Map namedPropertyItems; + + private Map> namedHints; + + public Set getPropertyGroups() { + return this.namedGroupItems.keySet(); + } + + public Set getPropertyNames() { + return this.namedPropertyItems.keySet(); + } + + public Collection getGroups() { + return this.namedGroupItems.values(); + } + + public Collection getProperties() { + return this.namedPropertyItems.values(); + } + + public ItemMetadata getGroup(String name) { + return this.namedGroupItems.get(name); + } + + public ItemMetadata getProperty(String name) { + return this.namedPropertyItems.get(name); + } + + public List getHints(String name) { + return this.namedHints.getOrDefault(name, emptyList()); + } + + @Override + public void run(String... args) throws Exception { + ConfigurationMetadata configurationMetadata = this.configurationMetadataReader.read(); + // ConfigurationMetadata can't return the underlying items as Map + init(configurationMetadata); + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); + } + + private void init(ConfigurationMetadata configurationMetadata) { + List items = configurationMetadata.getItems(); + initNamedGroupItems(items); + initNamedPropertyItems(items); + initNamedHints(configurationMetadata.getHints()); + } + + private void initNamedGroupItems(List items) { + this.namedGroupItems = createNamedItems(items, GROUP); + } + + private void initNamedPropertyItems(List items) { + this.namedPropertyItems = createNamedItems(items, PROPERTY); + } + + private void initNamedHints(List items) { + Map> namedHints = new LinkedHashMap<>(items.size()); + items.stream().forEach(itemHint -> { + List itemHints = namedHints.computeIfAbsent(itemHint.getName(), i -> new LinkedList<>()); + itemHints.add(itemHint); + }); + this.namedHints = namedHints; + } + + private Map createNamedItems(List items, ItemMetadata.ItemType itemType) { + Map namedItems = new LinkedHashMap<>(items.size()); + items.stream().filter(item -> item.isOfItemType(itemType)).forEach(item -> { + namedItems.put(item.getName(), item); + }); + return namedItems; + } +} From e3e5e756c56f090752db6b07452d343052346e52 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:29:35 +0800 Subject: [PATCH 18/51] Create ConfigurationMetadataRepositoryTest.java --- .../ConfigurationMetadataRepositoryTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java new file mode 100644 index 0000000..fa6df5d --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.GROUP; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.PROPERTY; + +/** + * {@link ConfigurationMetadataRepository} Test + * + * @author Mercy + * @see ConfigurationMetadataRepository + * @since 1.0.0 + */ +@SpringBootTest( + classes = { + ConfigurationMetadataRepository.class, + ConfigurationMetadataRepositoryTest.class, + }, + webEnvironment = SpringBootTest.WebEnvironment.NONE +) +public class ConfigurationMetadataRepositoryTest { + + @Autowired + private ConfigurationMetadataRepository repository; + + @Test + public void testGetter() { + assertGroups(); + } + + private void assertGroups() { + this.repository.getGroups().forEach(this::assertGroupItem); + this.repository.getPropertyGroups().stream() + .map(this.repository::getGroup).forEach(this::assertGroupItem); + } + + private void assertProperties() { + this.repository.getProperties().forEach(this::assertProperty); + this.repository.getPropertyNames().stream() + .map(this.repository::getProperty).forEach(this::assertProperty); + } + + private void assertGroupItem(ItemMetadata groupItem) { + assertTrue(groupItem.isOfItemType(GROUP)); + assertNotNull(groupItem.getName()); + assertNull(groupItem.getDefaultValue()); + assertNull(groupItem.getDescription()); + } + + private void assertProperty(ItemMetadata propertyItem) { + assertTrue(propertyItem.isOfItemType(PROPERTY)); + assertNotNull(propertyItem.getName()); + assertNotNull(propertyItem.getSourceType()); + assertNotNull(propertyItem.getType()); + assertNotNull(propertyItem.getDefaultValue()); + assertNotNull(propertyItem.getDescription()); + } +} From efb6a4572d9d0dba2cd2b5bf27f9972f9e197723 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:33:45 +0800 Subject: [PATCH 19/51] Update ConfigurationMetadataRepository.java --- .../ConfigurationMetadataRepository.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java index 1799ffc..5b9817a 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java @@ -21,9 +21,10 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.ItemHint; import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -46,40 +47,52 @@ public class ConfigurationMetadataRepository implements BeanClassLoaderAware, Co private ConfigurationMetadataReader configurationMetadataReader; - private Map namedGroupItems; + private Map namedGroups; - private Map namedPropertyItems; + private Map namedProperties; private Map> namedHints; + @NonNull public Set getPropertyGroups() { - return this.namedGroupItems.keySet(); + return this.namedGroups.keySet(); } + @NonNull public Set getPropertyNames() { - return this.namedPropertyItems.keySet(); + return this.namedProperties.keySet(); } + @NonNull public Collection getGroups() { - return this.namedGroupItems.values(); + return this.namedGroups.values(); } + @NonNull public Collection getProperties() { - return this.namedPropertyItems.values(); + return this.namedProperties.values(); } + @Nullable public ItemMetadata getGroup(String name) { - return this.namedGroupItems.get(name); + return this.namedGroups.get(name); } + @Nullable public ItemMetadata getProperty(String name) { - return this.namedPropertyItems.get(name); + return this.namedProperties.get(name); } + @NonNull public List getHints(String name) { return this.namedHints.getOrDefault(name, emptyList()); } + @NonNull + public ConfigurationMetadataReader getConfigurationMetadataReader() { + return configurationMetadataReader; + } + @Override public void run(String... args) throws Exception { ConfigurationMetadata configurationMetadata = this.configurationMetadataReader.read(); @@ -100,11 +113,11 @@ private void init(ConfigurationMetadata configurationMetadata) { } private void initNamedGroupItems(List items) { - this.namedGroupItems = createNamedItems(items, GROUP); + this.namedGroups = createNamedItems(items, GROUP); } private void initNamedPropertyItems(List items) { - this.namedPropertyItems = createNamedItems(items, PROPERTY); + this.namedProperties = createNamedItems(items, PROPERTY); } private void initNamedHints(List items) { From 9f0a0482fb03ebec3dcadd265dbeeadff88b74d5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:41:29 +0800 Subject: [PATCH 20/51] Update ConfigurationMetadataEndpoint.java --- .../ConfigurationMetadataEndpoint.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java index a2ac267..8c91bc7 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java @@ -16,10 +16,14 @@ */ package io.microsphere.spring.boot.actuate.endpoint; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; +import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; + +import java.util.Collection; /** * {@link Endpoint @Endpoint} to expose the {@link ConfigurationMetadata Configuration Metadata} that was generated by @@ -27,19 +31,49 @@ * * @author Mercy * @see ConfigurationMetadata + * @see ConfigurationMetadataRepository * @since 1.0.0 */ @Endpoint(id = "configMetadata") public class ConfigurationMetadataEndpoint { - private final ConfigurationMetadataReader configurationMetadataReader; + private final ConfigurationMetadataRepository configurationMetadataRepository; - public ConfigurationMetadataEndpoint(ConfigurationMetadataReader configurationMetadataReader) { - this.configurationMetadataReader = configurationMetadataReader; + public ConfigurationMetadataEndpoint(ConfigurationMetadataRepository configurationMetadataRepository) { + this.configurationMetadataRepository = configurationMetadataRepository; } @ReadOperation - public ConfigurationMetadata getConfigurationMetadata() { - return this.configurationMetadataReader.read(); + public ConfigurationMetadataDescriptor getConfigurationMetadata() { + ConfigurationMetadataDescriptor configurationMetadata = new ConfigurationMetadataDescriptor(); + configurationMetadata.groups = this.configurationMetadataRepository.getGroups(); + configurationMetadata.properties = this.configurationMetadataRepository.getProperties(); + return configurationMetadata; + } + + /** + * The Descriptor class for {@link ConfigurationMetadata} + */ + public static class ConfigurationMetadataDescriptor implements OperationResponseBody { + + private Collection groups; + + private Collection properties; + + public Collection getGroups() { + return groups; + } + + public void setGroups(Collection groups) { + this.groups = groups; + } + + public Collection getProperties() { + return properties; + } + + public void setProperties(Collection properties) { + this.properties = properties; + } } } From 925e00918739a0650a31611ebb712832a6938626 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:41:33 +0800 Subject: [PATCH 21/51] Update ConfigurationPropertiesEndpoint.java --- .../ConfigurationPropertiesEndpoint.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java index 7c4afd3..0f4d4a6 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java @@ -17,15 +17,20 @@ package io.microsphere.spring.boot.actuate.endpoint; import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.List; /** * {@link Endpoint @Endpoint} to expose the configuration properties * * @author Mercy * @see ConfigurationMetadata + * @see ConfigurationProperties * @since 1.0.0 */ @Endpoint(id = "configProperties") @@ -38,7 +43,34 @@ public ConfigurationPropertiesEndpoint(ClassLoader classLoader) { } @ReadOperation - public ConfigurationMetadata getConfigurationMetadata() { - return this.configurationMetadataReader.read(); + public ConfigurationPropertiesDescriptor getConfigurationProperties() { + ConfigurationPropertiesDescriptor configurationProperties = new ConfigurationPropertiesDescriptor(); + return configurationProperties; + } + + public static class ConfigurationPropertiesDescriptor implements OperationResponseBody { + + private List configurationProperties; + + public List getConfigurationProperties() { + return configurationProperties; + } + + public void setConfigurationProperties(List configurationProperties) { + this.configurationProperties = configurationProperties; + } + } + + public static class ConfigurationPropertyDescriptor { + + private String name; + + private String type; + + private Object value; + + private Object defaultValue; + + } } From f0ce465d8ea51c1bbcb2a01f9c5308b2e7d09a04 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:41:36 +0800 Subject: [PATCH 22/51] Update ActuatorEndpointsAutoConfiguration.java --- .../ActuatorEndpointsAutoConfiguration.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index a4c9b55..bbb6f85 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -21,6 +21,7 @@ import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -63,27 +64,21 @@ public WebEndpoints webEndpoints(WebEndpointsSupplier webEndpointsSupplier) { } @ConditionalOnConfigurationProcessorPresent - static class ConfigurationProcessorConfiguration implements BeanClassLoaderAware { - - private ClassLoader classLoader; + static class ConfigurationProcessorConfiguration { @Bean @ConditionalOnMissingBean - public ConfigurationMetadataReader configurationMetadataReader() { - return new ConfigurationMetadataReader(this.classLoader); + public ConfigurationMetadataRepository configurationMetadataRepository() { + return new ConfigurationMetadataRepository(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint - public ConfigurationMetadataEndpoint configurationMetadataEndpoint(ConfigurationMetadataReader configurationMetadataReader) { - return new ConfigurationMetadataEndpoint(configurationMetadataReader); + public ConfigurationMetadataEndpoint configurationMetadataEndpoint(ConfigurationMetadataRepository configurationMetadataRepository) { + return new ConfigurationMetadataEndpoint(configurationMetadataRepository); } - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.classLoader = classLoader; - } } @Override From b27631bb9006422641eb774d214ce5efc8e751a8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 16 Nov 2024 19:41:38 +0800 Subject: [PATCH 23/51] Update ActuatorEndpointsAutoConfigurationTest.java --- .../ActuatorEndpointsAutoConfigurationTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java index a48b036..f713345 100644 --- a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java +++ b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java @@ -54,8 +54,9 @@ public void testInvokeReadOperations() { @Test public void testGetConfigurationMetadata() { - ConfigurationMetadata configurationMetadata = configurationMetadataEndpoint.getConfigurationMetadata(); - assertFalse(configurationMetadata.getItems().isEmpty()); + ConfigurationMetadataEndpoint.ConfigurationMetadataDescriptor configurationMetadata = configurationMetadataEndpoint.getConfigurationMetadata(); + assertFalse(configurationMetadata.getGroups().isEmpty()); + assertFalse(configurationMetadata.getProperties().isEmpty()); } public static void main(String[] args) { From 9d96034d6e650e5bdcc7e2d775c777cd4e90abe0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 18 Nov 2024 16:06:10 +0800 Subject: [PATCH 24/51] Create ConfigurationPropertyDescriptor.java --- .../ConfigurationPropertyDescriptor.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java new file mode 100644 index 0000000..66cc22b --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertyResolver; +import org.springframework.core.env.PropertySource; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; + +/** + * The descriptor class of the Spring Configuration Property + * + * @author Mercy + * @see Environment + * @see PropertySource + * @since 1.0.0 + */ +public class ConfigurationPropertyDescriptor { + + private String name; + + private String type; + + private Object value; + + private Object defaultValue; + + private Usage usage; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public Object getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } + + public Usage getUsage() { + return usage; + } + + public void setUsage(Usage usage) { + this.usage = usage; + } + + /** + * The configuration property usage + * + * @see ConfigurationProperties + * @see Value + * @see PropertyResolver#resolvePlaceholders(String) + * @see PropertyResolver#getProperty(String) + */ + public enum Usage { + + /** + * Indicates the configuration property was used for {@link ConfigurationProperties @ConfigurationProperties} + * Bean. + */ + CONFIGURATION_PROPERTIES_BEAN, + + /** + * Indicates the configuration property was used to inject the Beans' {@link Member member}({@link Field field}, + * {@link Method method} and {@link Constructor constructor}) that was annotated {@link Value @Value}. + */ + VALUE_MEMBER, + + /** + * Indicates the configuration property was used to {@link PropertyResolver#resolvePlaceholders(String) resolve the placeholders} + */ + PLACEHOLDER, + + /** + * Indicates the configuration property was used to {@link PropertyResolver#getProperty(String, Class) get the property} + */ + DEFAULT, + } +} From 7c887f3cff96f47612acaf2379c4c57802ae5f7d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 22 Nov 2024 14:59:29 +0800 Subject: [PATCH 25/51] Update ConfigurationPropertiesEndpoint.java --- .../ConfigurationPropertiesEndpoint.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java index 0f4d4a6..96fea04 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java @@ -16,17 +16,21 @@ */ package io.microsphere.spring.boot.actuate.endpoint; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; +import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; +import io.microsphere.spring.boot.configuration.metadata.ContextConfigurationPropertyDescriptor; import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.event.EventListener; import java.util.List; /** - * {@link Endpoint @Endpoint} to expose the configuration properties + * {@link Endpoint @Endpoint} to expose the configuration properties. * * @author Mercy * @see ConfigurationMetadata @@ -36,10 +40,15 @@ @Endpoint(id = "configProperties") public class ConfigurationPropertiesEndpoint { - private final ConfigurationMetadataReader configurationMetadataReader; + private final ConfigurationMetadataRepository configurationMetadataRepository; - public ConfigurationPropertiesEndpoint(ClassLoader classLoader) { - this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); + public ConfigurationPropertiesEndpoint(ConfigurationMetadataRepository configurationMetadataRepository) { + this.configurationMetadataRepository = configurationMetadataRepository; + } + + @EventListener(ApplicationReadyEvent.class) + public void onApplicationReadyEvent(ApplicationReadyEvent event) { + ConfigurableApplicationContext context = event.getApplicationContext(); } @ReadOperation @@ -48,29 +57,19 @@ public ConfigurationPropertiesDescriptor getConfigurationProperties() { return configurationProperties; } + public static class ConfigurationPropertiesDescriptor implements OperationResponseBody { - private List configurationProperties; + private List configurationProperties; - public List getConfigurationProperties() { + public List getConfigurationProperties() { return configurationProperties; } - public void setConfigurationProperties(List configurationProperties) { + public void setConfigurationProperties(List configurationProperties) { this.configurationProperties = configurationProperties; } } - public static class ConfigurationPropertyDescriptor { - - private String name; - - private String type; - private Object value; - - private Object defaultValue; - - - } } From ce9b5cb6ebdea857012f26ad7bb9906a84fb8d29 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 22 Nov 2024 14:59:35 +0800 Subject: [PATCH 26/51] Delete ConfigurationPropertyDescriptor.java --- .../ConfigurationPropertyDescriptor.java | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java deleted file mode 100644 index 66cc22b..0000000 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationPropertyDescriptor.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; -import org.springframework.core.env.PropertySource; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; - -/** - * The descriptor class of the Spring Configuration Property - * - * @author Mercy - * @see Environment - * @see PropertySource - * @since 1.0.0 - */ -public class ConfigurationPropertyDescriptor { - - private String name; - - private String type; - - private Object value; - - private Object defaultValue; - - private Usage usage; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - - public Object getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } - - public Usage getUsage() { - return usage; - } - - public void setUsage(Usage usage) { - this.usage = usage; - } - - /** - * The configuration property usage - * - * @see ConfigurationProperties - * @see Value - * @see PropertyResolver#resolvePlaceholders(String) - * @see PropertyResolver#getProperty(String) - */ - public enum Usage { - - /** - * Indicates the configuration property was used for {@link ConfigurationProperties @ConfigurationProperties} - * Bean. - */ - CONFIGURATION_PROPERTIES_BEAN, - - /** - * Indicates the configuration property was used to inject the Beans' {@link Member member}({@link Field field}, - * {@link Method method} and {@link Constructor constructor}) that was annotated {@link Value @Value}. - */ - VALUE_MEMBER, - - /** - * Indicates the configuration property was used to {@link PropertyResolver#resolvePlaceholders(String) resolve the placeholders} - */ - PLACEHOLDER, - - /** - * Indicates the configuration property was used to {@link PropertyResolver#getProperty(String, Class) get the property} - */ - DEFAULT, - } -} From 21e93af027a10f603913371ce67dc8822f289683 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 22 Nov 2024 14:59:37 +0800 Subject: [PATCH 27/51] Create ContextConfigurationPropertyDescriptor.java --- ...ontextConfigurationPropertyDescriptor.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java new file mode 100644 index 0000000..56bf670 --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.configuration.metadata; + +import io.microsphere.spring.config.metadata.ConfigurationPropertyDescriptor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertyResolver; +import org.springframework.core.env.PropertySource; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.EnumSet; +import java.util.Set; + +/** + * The context descriptor class of the Spring Configuration Property + * + * @author Mercy + * @see ConfigurationPropertyDescriptor + * @since 1.0.0 + */ +public class ContextConfigurationPropertyDescriptor extends ConfigurationPropertyDescriptor { + + private Set usages; + + public Set getUsages() { + return usages; + } + + public void setUsages(Set usages) { + this.usages = usages; + } + + /** + * The configuration property usage + * + * @see ConfigurationProperties + * @see Value + * @see PropertyResolver#resolvePlaceholders(String) + * @see PropertyResolver#getProperty(String) + */ + public enum Usage { + + /** + * Indicates the configuration property was used for {@link ConfigurationProperties @ConfigurationProperties} + * Bean. + */ + CONFIGURATION_PROPERTIES_BEAN, + + /** + * Indicates the configuration property was used to inject the Beans' {@link Member member}({@link Field field}, + * {@link Method method} and {@link Constructor constructor}) that was annotated {@link Value @Value}. + */ + VALUE_MEMBER, + + /** + * Indicates the configuration property was used to {@link PropertyResolver#resolvePlaceholders(String) resolve the placeholders} + */ + PLACEHOLDER, + + /** + * Indicates the configuration property was used to {@link PropertyResolver#getProperty(String, Class) get the property} + */ + DEFAULT, + } +} From d96b1c558b135bac4d6f5f7019c3e526879840dd Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 22 Nov 2024 18:38:20 +0800 Subject: [PATCH 28/51] Update spring.factories --- .../src/main/resources/META-INF/spring.factories | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories index fe59ee9..480c934 100644 --- a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -27,4 +27,8 @@ io.microsphere.spring.boot.autoconfigure.ConfigurableAutoConfigurationImportFilt # DefaultPropertiesPostProcessor io.microsphere.spring.boot.env.DefaultPropertiesPostProcessor=\ -io.microsphere.spring.boot.env.SpringApplicationDefaultPropertiesPostProcessor \ No newline at end of file +io.microsphere.spring.boot.env.SpringApplicationDefaultPropertiesPostProcessor + +# ApplicationContextInitializer +org.springframework.context.ApplicationContextInitializer=\ +io.microsphere.spring.core.env.ListenableConfigurableEnvironmentInitializer \ No newline at end of file From 2134f5c7b3ba946b267ed7fd24d56923c6260de5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sat, 23 Nov 2024 19:12:27 +0800 Subject: [PATCH 29/51] Update spring.factories --- .../src/main/resources/META-INF/spring.factories | 1 + 1 file changed, 1 insertion(+) diff --git a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories index 480c934..76f383e 100644 --- a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -31,4 +31,5 @@ io.microsphere.spring.boot.env.SpringApplicationDefaultPropertiesPostProcessor # ApplicationContextInitializer org.springframework.context.ApplicationContextInitializer=\ +io.microsphere.spring.beans.factory.support.ListenableAutowireCandidateResolverInitializer,\ io.microsphere.spring.core.env.ListenableConfigurableEnvironmentInitializer \ No newline at end of file From 388bcbcddf32358fb8f8850cc258f14f72d63d7b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:36:53 +0800 Subject: [PATCH 30/51] Create application.properties --- .../src/test/resources/application.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 microsphere-spring-boot-actuator/src/test/resources/application.properties diff --git a/microsphere-spring-boot-actuator/src/test/resources/application.properties b/microsphere-spring-boot-actuator/src/test/resources/application.properties new file mode 100644 index 0000000..1636c41 --- /dev/null +++ b/microsphere-spring-boot-actuator/src/test/resources/application.properties @@ -0,0 +1 @@ +management.endpoint.loggers.enabled = false \ No newline at end of file From 9f91e50b7a82f89c1d2083dc02c5892bc6e59404 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:37:09 +0800 Subject: [PATCH 31/51] Delete ConfigurationMetadataReader.java --- .../metadata/ConfigurationMetadataReader.java | 161 ------------------ 1 file changed, 161 deletions(-) delete mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java deleted file mode 100644 index b648799..0000000 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReader.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import io.microsphere.logging.Logger; -import io.microsphere.logging.LoggerFactory; -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; -import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.lang.NonNull; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import static io.microsphere.text.FormatUtils.format; -import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; -import static io.microsphere.util.StringUtils.replace; -import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX; - -/** - * The Reader of {@link ConfigurationMetadata} - * - * @author Mercy - * @see ConfigurationMetadata - * @since 1.0.0 - */ -public class ConfigurationMetadataReader { - - private static final Logger logger = LoggerFactory.getLogger(ConfigurationMetadataReader.class); - - public static final String METADATA_RESOURCE_NAME = "spring-configuration-metadata.json"; - - public static final String ADDITIONAL_METADATA_RESOURCE_NAME = "additional-spring-configuration-metadata.json"; - - private static final String META_INFO_PATH = "/META-INF/"; - - public static final String METADATA_RESOURCE_PATH = META_INFO_PATH + METADATA_RESOURCE_NAME; - - public static final String ADDITIONAL_METADATA_RESOURCE_PATH = META_INFO_PATH + ADDITIONAL_METADATA_RESOURCE_NAME; - - public static final String METADATA_RESOURCE_PATTERN_PATH = CLASSPATH_ALL_URL_PREFIX + METADATA_RESOURCE_PATH; - - public static final String ADDITIONAL_METADATA_RESOURCE_PATTERN_PATH = CLASSPATH_ALL_URL_PREFIX + ADDITIONAL_METADATA_RESOURCE_PATH; - - private final ResourcePatternResolver resourcePatternResolver; - - public ConfigurationMetadataReader() { - this(getDefaultClassLoader()); - } - - public ConfigurationMetadataReader(ClassLoader classLoader) { - this.resourcePatternResolver = new PathMatchingResourcePatternResolver(classLoader); - } - - public ConfigurationMetadata read() { - ConfigurationMetadata configurationMetadata = new ConfigurationMetadata(); - Resource[] metadataResources = getMetadataResources(); - int metadataResourcesSize = metadataResources.length; - Set processedAdditionalMetadataResources = new HashSet<>(metadataResourcesSize); - for (int i = 0; i < metadataResourcesSize; i++) { - Resource resource = metadataResources[i]; - processConfigurationMetadata(configurationMetadata, resource, processedAdditionalMetadataResources); - } - Resource[] additionalMetadataResources = getAdditionalMetadataResources(); - for (Resource additionalMetadataResource : additionalMetadataResources) { - if (processedAdditionalMetadataResources.remove(additionalMetadataResource)) { - continue; - } - processConfigurationMetadata(configurationMetadata, additionalMetadataResource); - } - return configurationMetadata; - } - - private void processConfigurationMetadata(ConfigurationMetadata configurationMetadata, Resource metadataResource, - Set processedAdditionalMetadataResources) { - processConfigurationMetadata(configurationMetadata, metadataResource); - tryProcessAdditionalMetadataResource(configurationMetadata, metadataResource, processedAdditionalMetadataResources); - } - - private void tryProcessAdditionalMetadataResource(ConfigurationMetadata configurationMetadata, Resource metadataResource, - Set processedAdditionalMetadataResources) { - try { - URI uri = metadataResource.getURI(); - String metadataResourcePath = uri.toString(); - String additionalMetadataResourcePath = replace(metadataResourcePath, METADATA_RESOURCE_NAME, ADDITIONAL_METADATA_RESOURCE_NAME); - Resource additionalMetadataResource = this.resourcePatternResolver.getResource(additionalMetadataResourcePath); - if (additionalMetadataResource.exists()) { - processConfigurationMetadata(configurationMetadata, additionalMetadataResource); - processedAdditionalMetadataResources.add(additionalMetadataResource); - } else { - if (logger.isDebugEnabled()) { - logger.debug("The Additional Configuration Metadata resource[{}] can't be found", additionalMetadataResource); - } - } - } catch (IOException e) { - String message = format("The Additional Configuration Metadata resource[{}] can't be open", metadataResource); - throw new RuntimeException(message, e); - } - } - - private void processConfigurationMetadata(ConfigurationMetadata configurationMetadata, Resource metadataResource) { - ConfigurationMetadata metadata = loadConfigurationMetadata(metadataResource); - configurationMetadata.merge(metadata); - } - - private ConfigurationMetadata loadConfigurationMetadata(Resource metadataResource) { - JsonMarshaller jsonMarshaller = new JsonMarshaller(); - final ConfigurationMetadata configurationMetadata; - try (InputStream inputStream = metadataResource.getInputStream()) { - configurationMetadata = jsonMarshaller.read(inputStream); - if (logger.isDebugEnabled()) { - logger.debug("Loaded the Configuration Metadata resource[{}] : {}", metadataResource, configurationMetadata); - } - } catch (Throwable e) { - String message = format("The Configuration Metadata resource[{}] can't be loaded", metadataResource); - throw new RuntimeException(message, e); - } - return configurationMetadata; - } - - @NonNull - private Resource[] getMetadataResources() { - return getResources(METADATA_RESOURCE_PATTERN_PATH); - } - - @NonNull - private Resource[] getAdditionalMetadataResources() { - return getResources(ADDITIONAL_METADATA_RESOURCE_PATTERN_PATH); - } - - @NonNull - private Resource[] getResources(String metadataResourcePatternPath) { - Resource[] metadataResources = null; - try { - metadataResources = this.resourcePatternResolver.getResources(metadataResourcePatternPath); - } catch (IOException e) { - String message = format("The Configuration Metadata resources[pattern : {}] can't be read", metadataResourcePatternPath); - throw new RuntimeException(message, e); - } - return metadataResources; - } -} From b71d5ec3ce7dacbee9dc3e99aa850f237a77adc0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:37:14 +0800 Subject: [PATCH 32/51] Delete ConfigurationMetadataRepository.java --- .../ConfigurationMetadataRepository.java | 139 ------------------ 1 file changed, 139 deletions(-) delete mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java deleted file mode 100644 index 5b9817a..0000000 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepository.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; -import org.springframework.boot.configurationprocessor.metadata.ItemHint; -import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static java.util.Collections.emptyList; -import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.GROUP; -import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.PROPERTY; - -/** - * The Repository for {@link ConfigurationMetadata} - * - * @author Mercy - * @see ConfigurationMetadata - * @see ConfigurationMetadataReader - * @since 1.0.0 - */ -public class ConfigurationMetadataRepository implements BeanClassLoaderAware, CommandLineRunner { - - private ConfigurationMetadataReader configurationMetadataReader; - - private Map namedGroups; - - private Map namedProperties; - - private Map> namedHints; - - @NonNull - public Set getPropertyGroups() { - return this.namedGroups.keySet(); - } - - @NonNull - public Set getPropertyNames() { - return this.namedProperties.keySet(); - } - - @NonNull - public Collection getGroups() { - return this.namedGroups.values(); - } - - @NonNull - public Collection getProperties() { - return this.namedProperties.values(); - } - - @Nullable - public ItemMetadata getGroup(String name) { - return this.namedGroups.get(name); - } - - @Nullable - public ItemMetadata getProperty(String name) { - return this.namedProperties.get(name); - } - - @NonNull - public List getHints(String name) { - return this.namedHints.getOrDefault(name, emptyList()); - } - - @NonNull - public ConfigurationMetadataReader getConfigurationMetadataReader() { - return configurationMetadataReader; - } - - @Override - public void run(String... args) throws Exception { - ConfigurationMetadata configurationMetadata = this.configurationMetadataReader.read(); - // ConfigurationMetadata can't return the underlying items as Map - init(configurationMetadata); - } - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.configurationMetadataReader = new ConfigurationMetadataReader(classLoader); - } - - private void init(ConfigurationMetadata configurationMetadata) { - List items = configurationMetadata.getItems(); - initNamedGroupItems(items); - initNamedPropertyItems(items); - initNamedHints(configurationMetadata.getHints()); - } - - private void initNamedGroupItems(List items) { - this.namedGroups = createNamedItems(items, GROUP); - } - - private void initNamedPropertyItems(List items) { - this.namedProperties = createNamedItems(items, PROPERTY); - } - - private void initNamedHints(List items) { - Map> namedHints = new LinkedHashMap<>(items.size()); - items.stream().forEach(itemHint -> { - List itemHints = namedHints.computeIfAbsent(itemHint.getName(), i -> new LinkedList<>()); - itemHints.add(itemHint); - }); - this.namedHints = namedHints; - } - - private Map createNamedItems(List items, ItemMetadata.ItemType itemType) { - Map namedItems = new LinkedHashMap<>(items.size()); - items.stream().filter(item -> item.isOfItemType(itemType)).forEach(item -> { - namedItems.put(item.getName(), item); - }); - return namedItems; - } -} From 0a5b64dfb56f682f1d80313a325c5cc3ea87922e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:37:19 +0800 Subject: [PATCH 33/51] Delete ContextConfigurationPropertyDescriptor.java --- ...ontextConfigurationPropertyDescriptor.java | 84 ------------------- 1 file changed, 84 deletions(-) delete mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java deleted file mode 100644 index 56bf670..0000000 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/configuration/metadata/ContextConfigurationPropertyDescriptor.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import io.microsphere.spring.config.metadata.ConfigurationPropertyDescriptor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; -import org.springframework.core.env.PropertySource; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.EnumSet; -import java.util.Set; - -/** - * The context descriptor class of the Spring Configuration Property - * - * @author Mercy - * @see ConfigurationPropertyDescriptor - * @since 1.0.0 - */ -public class ContextConfigurationPropertyDescriptor extends ConfigurationPropertyDescriptor { - - private Set usages; - - public Set getUsages() { - return usages; - } - - public void setUsages(Set usages) { - this.usages = usages; - } - - /** - * The configuration property usage - * - * @see ConfigurationProperties - * @see Value - * @see PropertyResolver#resolvePlaceholders(String) - * @see PropertyResolver#getProperty(String) - */ - public enum Usage { - - /** - * Indicates the configuration property was used for {@link ConfigurationProperties @ConfigurationProperties} - * Bean. - */ - CONFIGURATION_PROPERTIES_BEAN, - - /** - * Indicates the configuration property was used to inject the Beans' {@link Member member}({@link Field field}, - * {@link Method method} and {@link Constructor constructor}) that was annotated {@link Value @Value}. - */ - VALUE_MEMBER, - - /** - * Indicates the configuration property was used to {@link PropertyResolver#resolvePlaceholders(String) resolve the placeholders} - */ - PLACEHOLDER, - - /** - * Indicates the configuration property was used to {@link PropertyResolver#getProperty(String, Class) get the property} - */ - DEFAULT, - } -} From d29cc84b6a85b89a8359d98475389d9a1680a33a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:37:59 +0800 Subject: [PATCH 34/51] Update --- .../src/main/resources/META-INF/spring.factories | 10 +++++----- .../metadata/ConfigurationMetadataReaderTest.java | 1 + .../metadata/ConfigurationMetadataRepositoryTest.java | 1 + .../ActuatorEndpointsAutoConfiguration.java | 4 +--- .../endpoint/ConfigurationMetadataEndpoint.java | 2 +- .../endpoint/ConfigurationPropertiesEndpoint.java | 10 +++++----- .../ActuatorEndpointsAutoConfigurationTest.java | 9 +++++++-- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories index 76f383e..aeb2f19 100644 --- a/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/microsphere-core-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,6 +1,10 @@ # ApplicationContextInitializer org.springframework.context.ApplicationContextInitializer=\ -io.microsphere.spring.boot.report.ConditionEvaluationReportInitializer +io.microsphere.spring.context.event.EventPublishingBeanInitializer,\ +io.microsphere.spring.boot.report.ConditionEvaluationReportInitializer,\ +io.microsphere.spring.beans.factory.support.ListenableAutowireCandidateResolverInitializer,\ +io.microsphere.spring.core.env.ListenableConfigurableEnvironmentInitializer,\ +io.microsphere.spring.boot.env.config.OriginTrackedConfigurationPropertyInitializer # SpringApplicationRunListener org.springframework.boot.SpringApplicationRunListener=\ @@ -29,7 +33,3 @@ io.microsphere.spring.boot.autoconfigure.ConfigurableAutoConfigurationImportFilt io.microsphere.spring.boot.env.DefaultPropertiesPostProcessor=\ io.microsphere.spring.boot.env.SpringApplicationDefaultPropertiesPostProcessor -# ApplicationContextInitializer -org.springframework.context.ApplicationContextInitializer=\ -io.microsphere.spring.beans.factory.support.ListenableAutowireCandidateResolverInitializer,\ -io.microsphere.spring.core.env.ListenableConfigurableEnvironmentInitializer \ No newline at end of file diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java index b94b9ae..7f0644a 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java @@ -16,6 +16,7 @@ */ package io.microsphere.spring.boot.configuration.metadata; +import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataReader; import org.junit.jupiter.api.Test; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java index fa6df5d..6058ee0 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java @@ -16,6 +16,7 @@ */ package io.microsphere.spring.boot.configuration.metadata; +import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index bbb6f85..edd12b2 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -20,12 +20,10 @@ import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataReader; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; +import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints; import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java index 8c91bc7..f67e152 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationMetadataEndpoint.java @@ -16,7 +16,7 @@ */ package io.microsphere.spring.boot.actuate.endpoint; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; +import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java index 96fea04..8e6c1e0 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/endpoint/ConfigurationPropertiesEndpoint.java @@ -16,8 +16,8 @@ */ package io.microsphere.spring.boot.actuate.endpoint; -import io.microsphere.spring.boot.configuration.metadata.ConfigurationMetadataRepository; -import io.microsphere.spring.boot.configuration.metadata.ContextConfigurationPropertyDescriptor; +import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; +import io.microsphere.spring.config.ConfigurationProperty; import org.springframework.boot.actuate.endpoint.OperationResponseBody; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -60,13 +60,13 @@ public ConfigurationPropertiesDescriptor getConfigurationProperties() { public static class ConfigurationPropertiesDescriptor implements OperationResponseBody { - private List configurationProperties; + private List configurationProperties; - public List getConfigurationProperties() { + public List getConfigurationProperties() { return configurationProperties; } - public void setConfigurationProperties(List configurationProperties) { + public void setConfigurationProperties(List configurationProperties) { this.configurationProperties = configurationProperties; } } diff --git a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java index f713345..7ce1881 100644 --- a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java +++ b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfigurationTest.java @@ -8,9 +8,9 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.TestPropertySource; import java.util.Map; @@ -27,8 +27,13 @@ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ActuatorEndpointsAutoConfigurationTest.class, - }) + }, + properties = { + "management.endpoint.loggers.enabled=false" + } +) @PropertySource(value = "classpath:META-INF/config/default/endpoints.properties") +@TestPropertySource(value = "classpath:META-INF/config/default/endpoints.properties") @EnableAutoConfiguration public class ActuatorEndpointsAutoConfigurationTest { From 676daaba603ec7cea526cc74dfb480feb00633ce Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:41:52 +0800 Subject: [PATCH 35/51] Create OriginTrackedConfigurationPropertyInitializer.java --- ...ackedConfigurationPropertyInitializer.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java new file mode 100644 index 0000000..2c6b123 --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.env.config; + +import io.microsphere.spring.context.event.BeanListenerAdapter; +import io.microsphere.spring.util.BeanRegistrar; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.boot.env.OriginTrackedMapPropertySource; +import org.springframework.boot.origin.Origin; +import org.springframework.boot.origin.OriginLookup; +import org.springframework.boot.origin.OriginTrackedValue; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; + +import java.util.LinkedHashMap; +import java.util.Map; + +import static io.microsphere.spring.util.BeanRegistrar.registerBean; + +/** + * {@link ApplicationContextInitializer} class supports origin tracked configuration property. + * + * @author Mercy + * @see ConfigurableEnvironment + * @since ApplicationContextInitializer + */ +public class OriginTrackedConfigurationPropertyInitializer extends BeanListenerAdapter + implements ApplicationContextInitializer { + + public static final String BEAN_NAME = "originTrackedConfigurationPropertyInitializer"; + + private boolean initialized = false; + + private ConfigurableApplicationContext applicationContext; + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + this.applicationContext = applicationContext; + ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; + registerBean(registry, BEAN_NAME, this); + } + + @Override + public void onBeforeBeanInstantiate(String beanName, RootBeanDefinition mergedBeanDefinition) { + if (initialized) { + return; + } + ConfigurableEnvironment environment = applicationContext.getEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + initializePropertySources(propertySources); + initialized = true; + } + + private void initializePropertySources(MutablePropertySources propertySources) { + for (PropertySource propertySource : propertySources) { + if (isPropertySourceCandidate(propertySource)) { + String name = propertySource.getName(); + PropertySource originTrackedPropertySource = createOriginTrackedPropertySource(propertySource); + propertySources.replace(name, originTrackedPropertySource); + } + } + } + + private boolean isPropertySourceCandidate(PropertySource propertySource) { + return (propertySource instanceof EnumerablePropertySource) && + !(propertySource instanceof OriginLookup); + } + + private PropertySource createOriginTrackedPropertySource(PropertySource propertySource) { + EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource; + String[] propertyNames = enumerablePropertySource.getPropertyNames(); + int size = propertyNames.length; + Map source = new LinkedHashMap<>(size); + for (int i = 0; i < size; i++) { + String propertyName = propertyNames[i]; + Object propertyValue = enumerablePropertySource.getProperty(propertyName); + if (propertyValue instanceof OriginTrackedValue) { + continue; + } + Origin origin = resolveOrigin(propertySource); + // propertyValue with origin + propertyValue = OriginTrackedValue.of(propertyValue, origin); + source.put(propertyName, propertyValue); + } + return new OriginTrackedMapPropertySource(propertySource.getName(), source); + } + + private Origin resolveOrigin(PropertySource propertySource) { + // TODO + return new NamedOrigin(propertySource.getName()); + } + + static class NamedOrigin implements Origin { + + private final String name; + + NamedOrigin(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } +} From 5be1ddacc0b98582614a7dc2d811d005b6667c81 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 24 Nov 2024 22:52:38 +0800 Subject: [PATCH 36/51] Refactor --- .../ConfigurationMetadataRepository.java | 138 ++++++++++++++++++ .../ConfigurationMetadataReaderTest.java | 40 ----- .../ConfigurationMetadataRepositoryTest.java | 82 ----------- .../ActuatorEndpointsAutoConfiguration.java | 11 +- 4 files changed, 147 insertions(+), 124 deletions(-) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/metadata/ConfigurationMetadataRepository.java delete mode 100644 microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java delete mode 100644 microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/metadata/ConfigurationMetadataRepository.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/metadata/ConfigurationMetadataRepository.java new file mode 100644 index 0000000..44efe6e --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/metadata/ConfigurationMetadataRepository.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.env.config.metadata; + +import io.microsphere.spring.boot.context.properties.metadata.ConfigurationMetadataReader; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; +import org.springframework.boot.configurationprocessor.metadata.ItemHint; +import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static java.util.Collections.emptyList; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.GROUP; +import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.PROPERTY; + +/** + * The Repository for {@link ConfigurationMetadata} + * + * @author Mercy + * @see ConfigurationMetadata + * @see ConfigurationMetadataReader + * @since 1.0.0 + */ +public class ConfigurationMetadataRepository implements CommandLineRunner { + + private final ConfigurationMetadataReader configurationMetadataReader; + + private Map namedGroups; + + private Map namedProperties; + + private Map> namedHints; + + public ConfigurationMetadataRepository(ConfigurationMetadataReader configurationMetadataReader) { + this.configurationMetadataReader = configurationMetadataReader; + } + + @NonNull + public Set getPropertyGroups() { + return this.namedGroups.keySet(); + } + + @NonNull + public Set getPropertyNames() { + return this.namedProperties.keySet(); + } + + @NonNull + public Collection getGroups() { + return this.namedGroups.values(); + } + + @NonNull + public Collection getProperties() { + return this.namedProperties.values(); + } + + @Nullable + public ItemMetadata getGroup(String name) { + return this.namedGroups.get(name); + } + + @Nullable + public ItemMetadata getProperty(String name) { + return this.namedProperties.get(name); + } + + @NonNull + public List getHints(String name) { + return this.namedHints.getOrDefault(name, emptyList()); + } + + @NonNull + public ConfigurationMetadataReader getConfigurationMetadataReader() { + return configurationMetadataReader; + } + + @Override + public void run(String... args) throws Exception { + ConfigurationMetadata configurationMetadata = this.configurationMetadataReader.read(); + // ConfigurationMetadata can't return the underlying items as Map + init(configurationMetadata); + } + + private void init(ConfigurationMetadata configurationMetadata) { + List items = configurationMetadata.getItems(); + initNamedGroupItems(items); + initNamedPropertyItems(items); + initNamedHints(configurationMetadata.getHints()); + } + + private void initNamedGroupItems(List items) { + this.namedGroups = createNamedItems(items, GROUP); + } + + private void initNamedPropertyItems(List items) { + this.namedProperties = createNamedItems(items, PROPERTY); + } + + private void initNamedHints(List items) { + Map> namedHints = new LinkedHashMap<>(items.size()); + items.stream().forEach(itemHint -> { + List itemHints = namedHints.computeIfAbsent(itemHint.getName(), i -> new LinkedList<>()); + itemHints.add(itemHint); + }); + this.namedHints = namedHints; + } + + private Map createNamedItems(List items, ItemMetadata.ItemType itemType) { + Map namedItems = new LinkedHashMap<>(items.size()); + items.stream().filter(item -> item.isOfItemType(itemType)).forEach(item -> { + namedItems.put(item.getName(), item); + }); + return namedItems; + } +} diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java deleted file mode 100644 index 7f0644a..0000000 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataReaderTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataReader; -import org.junit.jupiter.api.Test; -import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * {@link ConfigurationMetadataReader} Test - * - * @author Mercy - * @see ConfigurationMetadataReader - * @since 1.0.0 - */ -public class ConfigurationMetadataReaderTest { - - @Test - public void testRead() throws Throwable { - ConfigurationMetadataReader reader = new ConfigurationMetadataReader(); - ConfigurationMetadata metadata = reader.read(); - assertNotNull(metadata); - } -} diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java deleted file mode 100644 index 6058ee0..0000000 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/configuration/metadata/ConfigurationMetadataRepositoryTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 io.microsphere.spring.boot.configuration.metadata; - -import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.configurationprocessor.metadata.ItemMetadata; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.GROUP; -import static org.springframework.boot.configurationprocessor.metadata.ItemMetadata.ItemType.PROPERTY; - -/** - * {@link ConfigurationMetadataRepository} Test - * - * @author Mercy - * @see ConfigurationMetadataRepository - * @since 1.0.0 - */ -@SpringBootTest( - classes = { - ConfigurationMetadataRepository.class, - ConfigurationMetadataRepositoryTest.class, - }, - webEnvironment = SpringBootTest.WebEnvironment.NONE -) -public class ConfigurationMetadataRepositoryTest { - - @Autowired - private ConfigurationMetadataRepository repository; - - @Test - public void testGetter() { - assertGroups(); - } - - private void assertGroups() { - this.repository.getGroups().forEach(this::assertGroupItem); - this.repository.getPropertyGroups().stream() - .map(this.repository::getGroup).forEach(this::assertGroupItem); - } - - private void assertProperties() { - this.repository.getProperties().forEach(this::assertProperty); - this.repository.getPropertyNames().stream() - .map(this.repository::getProperty).forEach(this::assertProperty); - } - - private void assertGroupItem(ItemMetadata groupItem) { - assertTrue(groupItem.isOfItemType(GROUP)); - assertNotNull(groupItem.getName()); - assertNull(groupItem.getDefaultValue()); - assertNull(groupItem.getDescription()); - } - - private void assertProperty(ItemMetadata propertyItem) { - assertTrue(propertyItem.isOfItemType(PROPERTY)); - assertNotNull(propertyItem.getName()); - assertNotNull(propertyItem.getSourceType()); - assertNotNull(propertyItem.getType()); - assertNotNull(propertyItem.getDefaultValue()); - assertNotNull(propertyItem.getDescription()); - } -} diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java index edd12b2..428ad89 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java @@ -20,6 +20,7 @@ import io.microsphere.spring.boot.actuate.endpoint.ArtifactsEndpoint; import io.microsphere.spring.boot.actuate.endpoint.ConfigurationMetadataEndpoint; import io.microsphere.spring.boot.actuate.endpoint.WebEndpoints; +import io.microsphere.spring.boot.context.properties.metadata.ConfigurationMetadataReader; import io.microsphere.spring.boot.env.config.metadata.ConfigurationMetadataRepository; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; @@ -66,8 +67,14 @@ static class ConfigurationProcessorConfiguration { @Bean @ConditionalOnMissingBean - public ConfigurationMetadataRepository configurationMetadataRepository() { - return new ConfigurationMetadataRepository(); + public ConfigurationMetadataReader configurationMetadataReader() { + return new ConfigurationMetadataReader(); + } + + @Bean + @ConditionalOnMissingBean + public ConfigurationMetadataRepository configurationMetadataRepository(ConfigurationMetadataReader configurationMetadataReader) { + return new ConfigurationMetadataRepository(configurationMetadataReader); } @Bean From e632a69074c2c2b061533158d5264624daec8fe8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 17:32:33 +0800 Subject: [PATCH 37/51] Create PropertySourceLoaders.java --- .../boot/env/PropertySourceLoaders.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java new file mode 100644 index 0000000..06356ae --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.env; + +import io.microsphere.util.ClassLoaderUtils; +import org.springframework.boot.env.PropertySourceLoader; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.Resource; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; +import static org.springframework.core.io.support.SpringFactoriesLoader.loadFactories; + + +/** + * The composite {@link PropertySourceLoader} + * + * @author Mercy + * @see PropertySourceLoader + * @since 1.0.0 + */ +public class PropertySourceLoaders implements PropertySourceLoader { + + private final List loaders; + + public PropertySourceLoaders() { + this(getDefaultClassLoader()); + } + + public PropertySourceLoaders(ClassLoader classLoader) { + this(loadFactories(PropertySourceLoader.class, classLoader)); + } + + public PropertySourceLoaders(List loader) { + this.loaders = new ArrayList<>(loader.size()); + this.loaders.addAll(loader); + } + + @Override + public String[] getFileExtensions() { + String[] fileExtensions = loaders.stream() + .map(PropertySourceLoader::getFileExtensions) + .map(Arrays::asList) + .flatMap(List::stream) + .toArray(String[]::new); + return fileExtensions; + } + + @Override + public List> load(String name, Resource resource) throws IOException { + List> propertySources = new LinkedList<>(); + URL url = resource.getURL(); + for (PropertySourceLoader loader : loaders) { + if (supports(loader, url)) { + propertySources.addAll(loader.load(name, resource)); + } + } + return propertySources; + } + + private boolean supports(PropertySourceLoader loader, URL resourceURL) { + String[] fileExtensions = loader.getFileExtensions(); + String path = resourceURL.getPath(); + boolean supported = false; + for (String fileExtension : fileExtensions) { + if (path.endsWith(fileExtension)) { + supported = true; + break; + } + } + return supported; + } +} From ac29c13e95c6340afd6993e18634554d810463ee Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 17:32:35 +0800 Subject: [PATCH 38/51] Create PropertySourceLoadersTest.java --- .../boot/env/PropertySourceLoadersTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java new file mode 100644 index 0000000..837cc15 --- /dev/null +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 io.microsphere.spring.boot.env; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.env.OriginTrackedMapPropertySource; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; + +import java.io.IOException; +import java.util.List; + +import static io.microsphere.util.ArrayUtils.of; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link PropertySourceLoaders} + * + * @author Mercy + * @see PropertySourceLoaders + * @since 1.0.0 + */ +public class PropertySourceLoadersTest { + + private static final PropertySourceLoaders propertySourceLoaders = new PropertySourceLoaders(); + + private static final String TEST_RESOURCE_LOCATION = "classpath:/config/default/core.properties"; + + private static final String TEST_PROPERTY_NAME = "core"; + + @Test + public void testGetFileExtensions() { + String[] fileExtensions = propertySourceLoaders.getFileExtensions(); + assertArrayEquals(of("properties", "xml", "yml", "yaml"), fileExtensions); + } + + @Test + public void testLoad() throws IOException { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + Resource resource = resourceLoader.getResource(TEST_RESOURCE_LOCATION); + List> propertySources = propertySourceLoaders.load(TEST_PROPERTY_NAME, resource); + assertEquals(1, propertySources.size()); + + PropertySource propertySource = propertySources.get(0); + assertTrue(propertySource instanceof OriginTrackedMapPropertySource); + assertEquals(TEST_PROPERTY_NAME, propertySource.getName()); + assertEquals("graceful", propertySource.getProperty("server.shutdown")); + } +} From 48fa96d29dce1add8a3c6fead04da738404ce123 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 20:31:24 +0800 Subject: [PATCH 39/51] Update PropertySourceLoaders.java --- .../boot/env/PropertySourceLoaders.java | 70 +++++++++++++++++-- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java index 06356ae..acd1a17 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java @@ -16,24 +16,29 @@ */ package io.microsphere.spring.boot.env; -import io.microsphere.util.ClassLoaderUtils; +import io.microsphere.logging.Logger; +import io.microsphere.logging.LoggerFactory; import org.springframework.boot.env.PropertySourceLoader; +import org.springframework.boot.origin.OriginLookup; import org.springframework.core.env.PropertySource; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; import java.io.IOException; import java.net.URL; -import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; +import static io.microsphere.util.StringUtils.substringBetween; import static org.springframework.core.io.support.SpringFactoriesLoader.loadFactories; +import static org.springframework.util.StringUtils.hasText; /** - * The composite {@link PropertySourceLoader} + * The composite class of {@link PropertySourceLoader} with utilities features * * @author Mercy * @see PropertySourceLoader @@ -41,6 +46,10 @@ */ public class PropertySourceLoaders implements PropertySourceLoader { + private static final Logger logger = LoggerFactory.getLogger(PropertySourceLoaders.class); + + private final ResourceLoader resourceLoader; + private final List loaders; public PropertySourceLoaders() { @@ -48,12 +57,12 @@ public PropertySourceLoaders() { } public PropertySourceLoaders(ClassLoader classLoader) { - this(loadFactories(PropertySourceLoader.class, classLoader)); + this(new DefaultResourceLoader(classLoader)); } - public PropertySourceLoaders(List loader) { - this.loaders = new ArrayList<>(loader.size()); - this.loaders.addAll(loader); + public PropertySourceLoaders(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + this.loaders = loadFactories(PropertySourceLoader.class, resourceLoader.getClassLoader()); } @Override @@ -78,6 +87,47 @@ public List> load(String name, Resource resource) throws IOExc return propertySources; } + /** + * Reload the {@link PropertySource} as an instance of {@link PropertySource} with {@link OriginLookup} + * + * @param propertySource {@link PropertySource} + * @return an instance of {@link PropertySource} with {@link OriginLookup} + * @throws IOException + */ + public PropertySource reloadAsOriginTracked(PropertySource propertySource) throws IOException { + if (propertySource instanceof OriginLookup) { + debug("The PropertySource[name : '{}', class : '{}'] is already an instance of OriginLookup", + propertySource.getName(), propertySource.getClass().getName()); + return propertySource; + } + // the name is source from Resource#getDescription() + String name = propertySource.getName(); + String location = substringBetween(name, "[", "]"); + // the location or uri can be resolved from FileSystemResource, ClassPathResource and UrlResource + if (hasText(location)) { + return loadAsOriginTracked(name, location); + } + return propertySource; + } + + /** + * Load the {@link PropertySource} as an instance of {@link PropertySource} with {@link OriginLookup} + * + * @param name the name of {@link PropertySource} + * @param location the location of {@link Resource} for {@link PropertySource} + * @return an instance of {@link PropertySource} with {@link OriginLookup} + * @throws IOException + */ + public PropertySource loadAsOriginTracked(String name, String location) throws IOException { + Resource resource = resourceLoader.getResource(location); + List> propertySources = load(name, resource); + int size = propertySources.size(); + if (size > 1) { + throw new IllegalStateException("The resource : " + resource + " can load more than one PropertySource"); + } + return propertySources.get(0); + } + private boolean supports(PropertySourceLoader loader, URL resourceURL) { String[] fileExtensions = loader.getFileExtensions(); String path = resourceURL.getPath(); @@ -90,4 +140,10 @@ private boolean supports(PropertySourceLoader loader, URL resourceURL) { } return supported; } + + private void debug(String messagePattern, Object... args) { + if (logger.isDebugEnabled()) { + logger.debug(messagePattern, args); + } + } } From de9dfa30d8212ea3680b36c00a3e5b153371437b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 20:31:26 +0800 Subject: [PATCH 40/51] Update PropertySourceLoadersTest.java --- .../boot/env/PropertySourceLoadersTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java index 837cc15..6482b93 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/env/PropertySourceLoadersTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.env.OriginTrackedMapPropertySource; +import org.springframework.boot.origin.OriginLookup; import org.springframework.core.env.PropertySource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -29,6 +30,7 @@ import static io.microsphere.util.ArrayUtils.of; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -42,10 +44,10 @@ public class PropertySourceLoadersTest { private static final PropertySourceLoaders propertySourceLoaders = new PropertySourceLoaders(); - private static final String TEST_RESOURCE_LOCATION = "classpath:/config/default/core.properties"; - private static final String TEST_PROPERTY_NAME = "core"; + private static final String TEST_RESOURCE_LOCATION = "classpath:/config/default/core.properties"; + @Test public void testGetFileExtensions() { String[] fileExtensions = propertySourceLoaders.getFileExtensions(); @@ -60,6 +62,23 @@ public void testLoad() throws IOException { assertEquals(1, propertySources.size()); PropertySource propertySource = propertySources.get(0); + assertPropertySource(propertySource); + } + + @Test + public void testLoadAsOriginTracked() throws IOException { + PropertySource propertySource = propertySourceLoaders.loadAsOriginTracked(TEST_PROPERTY_NAME, TEST_RESOURCE_LOCATION); + assertTrue(propertySource instanceof OriginLookup); + assertPropertySource(propertySource); + } + + @Test + public void testReloadAsOriginTracked() throws IOException { + PropertySource propertySource = propertySourceLoaders.loadAsOriginTracked(TEST_PROPERTY_NAME, TEST_RESOURCE_LOCATION); + assertSame(propertySource, propertySourceLoaders.reloadAsOriginTracked(propertySource)); + } + + private void assertPropertySource(PropertySource propertySource) { assertTrue(propertySource instanceof OriginTrackedMapPropertySource); assertEquals(TEST_PROPERTY_NAME, propertySource.getName()); assertEquals("graceful", propertySource.getProperty("server.shutdown")); From 8d91976710d2ccc5226370640015eae315978e73 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 21:51:04 +0800 Subject: [PATCH 41/51] Update OriginTrackedConfigurationPropertyInitializer.java --- ...ackedConfigurationPropertyInitializer.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java index 2c6b123..bde9433 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -16,8 +16,11 @@ */ package io.microsphere.spring.boot.env.config; +import io.microsphere.logging.Logger; +import io.microsphere.logging.LoggerFactory; +import io.microsphere.spring.boot.env.PropertySourceLoaders; +import io.microsphere.spring.context.event.BeanFactoryListenerAdapter; import io.microsphere.spring.context.event.BeanListenerAdapter; -import io.microsphere.spring.util.BeanRegistrar; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -31,7 +34,9 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; +import org.springframework.core.io.support.ResourcePropertySource; +import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; @@ -44,40 +49,45 @@ * @see ConfigurableEnvironment * @since ApplicationContextInitializer */ -public class OriginTrackedConfigurationPropertyInitializer extends BeanListenerAdapter - implements ApplicationContextInitializer { +public class OriginTrackedConfigurationPropertyInitializer implements BeanFactoryListenerAdapter, ApplicationContextInitializer { public static final String BEAN_NAME = "originTrackedConfigurationPropertyInitializer"; + private static final Logger logger = LoggerFactory.getLogger(OriginTrackedConfigurationPropertyInitializer.class); + private boolean initialized = false; private ConfigurableApplicationContext applicationContext; + private PropertySourceLoaders propertySourceLoaders; + @Override public void initialize(ConfigurableApplicationContext applicationContext) { this.applicationContext = applicationContext; + this.propertySourceLoaders = new PropertySourceLoaders(applicationContext.getClassLoader()); ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; registerBean(registry, BEAN_NAME, this); } @Override - public void onBeforeBeanInstantiate(String beanName, RootBeanDefinition mergedBeanDefinition) { - if (initialized) { - return; - } + public void onBeanFactoryConfigurationFrozen(ConfigurableListableBeanFactory beanFactory) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); initializePropertySources(propertySources); - initialized = true; } private void initializePropertySources(MutablePropertySources propertySources) { for (PropertySource propertySource : propertySources) { if (isPropertySourceCandidate(propertySource)) { String name = propertySource.getName(); - PropertySource originTrackedPropertySource = createOriginTrackedPropertySource(propertySource); - propertySources.replace(name, originTrackedPropertySource); + try { + PropertySource originTrackedPropertySource = createOriginTrackedPropertySource(propertySource); + propertySources.replace(name, originTrackedPropertySource); + } catch (IOException e) { + logger.error("Failed to create the origin tracked PropertySource[name : '{}', class : '{}']", + name, propertySource.getClass().getName()); + } } } } @@ -87,7 +97,11 @@ private boolean isPropertySourceCandidate(PropertySource propertySource) { !(propertySource instanceof OriginLookup); } - private PropertySource createOriginTrackedPropertySource(PropertySource propertySource) { + private PropertySource createOriginTrackedPropertySource(PropertySource propertySource) throws IOException { + if (propertySource instanceof ResourcePropertySource) { + return propertySourceLoaders.reloadAsOriginTracked(propertySource); + } + EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource; String[] propertyNames = enumerablePropertySource.getPropertyNames(); int size = propertyNames.length; @@ -95,6 +109,7 @@ private PropertySource createOriginTrackedPropertySource(PropertySource property for (int i = 0; i < size; i++) { String propertyName = propertyNames[i]; Object propertyValue = enumerablePropertySource.getProperty(propertyName); + // Skip if propertyValue is OriginTrackedValue if (propertyValue instanceof OriginTrackedValue) { continue; } @@ -107,7 +122,7 @@ private PropertySource createOriginTrackedPropertySource(PropertySource property } private Origin resolveOrigin(PropertySource propertySource) { - // TODO + // TODO more Origin implementations return new NamedOrigin(propertySource.getName()); } From 7c59a04ef6d0663b275b84531cb47d50b45f1715 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 21:51:58 +0800 Subject: [PATCH 42/51] Update OriginTrackedConfigurationPropertyInitializer.java --- .../config/OriginTrackedConfigurationPropertyInitializer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java index bde9433..c60d562 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -20,10 +20,8 @@ import io.microsphere.logging.LoggerFactory; import io.microsphere.spring.boot.env.PropertySourceLoaders; import io.microsphere.spring.context.event.BeanFactoryListenerAdapter; -import io.microsphere.spring.context.event.BeanListenerAdapter; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.boot.env.OriginTrackedMapPropertySource; import org.springframework.boot.origin.Origin; import org.springframework.boot.origin.OriginLookup; From 1ff83cea1fabf06a1d8d0c2dbc69a8f909161748 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Mon, 25 Nov 2024 21:52:21 +0800 Subject: [PATCH 43/51] Update ConfigurableAutoConfigurationImportFilter.java --- .../autoconfigure/ConfigurableAutoConfigurationImportFilter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java index fecf5d5..649c43a 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java @@ -9,7 +9,6 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; import java.util.LinkedHashSet; import java.util.Set; From e057095c69abc8ebb89d7600fe3c74e2c370f80a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 27 Nov 2024 21:40:49 +0800 Subject: [PATCH 44/51] Update OriginTrackedConfigurationPropertyInitializer.java --- .../config/OriginTrackedConfigurationPropertyInitializer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java index c60d562..66d266b 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -52,9 +52,7 @@ public class OriginTrackedConfigurationPropertyInitializer implements BeanFactor public static final String BEAN_NAME = "originTrackedConfigurationPropertyInitializer"; private static final Logger logger = LoggerFactory.getLogger(OriginTrackedConfigurationPropertyInitializer.class); - - private boolean initialized = false; - + private ConfigurableApplicationContext applicationContext; private PropertySourceLoaders propertySourceLoaders; From 6b65eaa99fc39aa4d3418a5ec27f4697a61ea062 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 17:23:19 +0800 Subject: [PATCH 45/51] Polish #17 --- .../ConfigurableAutoConfigurationImportFilter.java | 4 ++-- ...ngConfigurationPropertiesBeanPropertyChangedListener.java | 4 ++-- .../boot/env/DefaultPropertiesApplicationListener.java | 4 ++-- .../microsphere/spring/boot/env/PropertySourceLoaders.java | 4 ++-- .../OriginTrackedConfigurationPropertyInitializer.java | 2 +- .../boot/autoconfigure/ApplicationAutoConfigurationTest.java | 5 ++--- .../context/config/BindableConfigurationBeanBinderTest.java | 2 +- .../src/test/resources/logback.xml | 2 +- .../spring/boot/actuate/env/DefaultPropertiesTest.java | 4 ++-- microsphere-spring-boot-parent/pom.xml | 2 +- pom.xml | 2 +- 11 files changed, 17 insertions(+), 18 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java index 649c43a..d9a9708 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/autoconfigure/ConfigurableAutoConfigurationImportFilter.java @@ -8,7 +8,6 @@ import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.util.Assert; import java.util.LinkedHashSet; import java.util.Set; @@ -18,6 +17,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableSet; +import static org.springframework.util.Assert.isInstanceOf; import static org.springframework.util.StringUtils.collectionToCommaDelimitedString; import static org.springframework.util.StringUtils.commaDelimitedListToSet; import static org.springframework.util.StringUtils.hasText; @@ -102,7 +102,7 @@ private static MutablePropertySources getPropertySources(Environment environment } private static ConfigurableEnvironment getConfigurableEnvironment(Environment environment) { - Assert.isInstanceOf(ConfigurableEnvironment.class, environment); + isInstanceOf(ConfigurableEnvironment.class, environment); return (ConfigurableEnvironment) environment; } diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java index 8a59423..6a44c56 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java @@ -30,7 +30,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.util.Assert; import java.util.HashMap; import java.util.Map; @@ -41,6 +40,7 @@ import static io.microsphere.spring.boot.context.properties.source.util.ConfigurationPropertyUtils.getPrefix; import static io.microsphere.spring.boot.context.properties.util.ConfigurationPropertiesUtils.CONFIGURATION_PROPERTIES_CLASS; import static io.microsphere.spring.boot.context.properties.util.ConfigurationPropertiesUtils.findConfigurationProperties; +import static org.springframework.util.Assert.isInstanceOf; /** * A {@link BindListener} implementation of {@link ConfigurationProperties @ConfigurationProperties} Bean to publish @@ -126,7 +126,7 @@ private void initConfigurationPropertiesBeanContexts(ConfigurableListableBeanFac @Override public void setApplicationContext(ApplicationContext context) throws BeansException { Class expectedType = CONFIGURABLE_APPLICATION_CONTEXT_CLASS; - Assert.isInstanceOf(expectedType, context, "The 'context' argument is not an instance of " + expectedType.getName()); + isInstanceOf(expectedType, context, "The 'context' argument is not an instance of " + expectedType.getName()); this.context = expectedType.cast(context); } diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java index 898ede2..debd8ac 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java @@ -27,8 +27,8 @@ import static io.microsphere.spring.boot.util.SpringApplicationUtils.getDefaultPropertiesResources; import static io.microsphere.spring.boot.util.SpringApplicationUtils.getResourceLoader; -import static io.microsphere.spring.util.PropertySourcesUtils.getDefaultProperties; -import static io.microsphere.spring.util.ResourceLoaderUtils.getResourcePatternResolver; +import static io.microsphere.spring.core.env.PropertySourcesUtils.getDefaultProperties; +import static io.microsphere.spring.core.io.ResourceLoaderUtils.getResourcePatternResolver; import static org.springframework.core.io.support.SpringFactoriesLoader.loadFactories; /** diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java index acd1a17..79a3fd4 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/PropertySourceLoaders.java @@ -17,7 +17,6 @@ package io.microsphere.spring.boot.env; import io.microsphere.logging.Logger; -import io.microsphere.logging.LoggerFactory; import org.springframework.boot.env.PropertySourceLoader; import org.springframework.boot.origin.OriginLookup; import org.springframework.core.env.PropertySource; @@ -31,6 +30,7 @@ import java.util.LinkedList; import java.util.List; +import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; import static io.microsphere.util.StringUtils.substringBetween; import static org.springframework.core.io.support.SpringFactoriesLoader.loadFactories; @@ -46,7 +46,7 @@ */ public class PropertySourceLoaders implements PropertySourceLoader { - private static final Logger logger = LoggerFactory.getLogger(PropertySourceLoaders.class); + private static final Logger logger = getLogger(PropertySourceLoaders.class); private final ResourceLoader resourceLoader; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java index 66d266b..5fdfaa0 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -38,7 +38,7 @@ import java.util.LinkedHashMap; import java.util.Map; -import static io.microsphere.spring.util.BeanRegistrar.registerBean; +import static io.microsphere.spring.beans.factory.support.BeanRegistrar.registerBean; /** * {@link ApplicationContextInitializer} class supports origin tracked configuration property. diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java index 6bf3184..5a3702e 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java @@ -65,7 +65,7 @@ static class TestConfig { @Autowired private ObjectProvider loggingBeanListenerObjectProvider; - @Resource(name = "io.microsphere.spring.context.event.BeanTimeStatistics#0") + @Resource private BeanTimeStatistics beanTimeStatistics; @Resource(type = LoggingBeanListener.class) @@ -77,8 +77,7 @@ public void setLoggingBeanListener(LoggingBeanListener loggingBeanListener) { } public TestConfig(ObjectProvider beanListeners, - ObjectProvider> beanListenersList, - @Qualifier("io.microsphere.spring.context.event.LoggingBeanListener#0") LoggingBeanListener loggingBeanListener) { + ObjectProvider> beanListenersList) { this.beanListeners = beanListeners; this.beanListenersList = beanListenersList; } diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java index 05ee67a..3eac07e 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java @@ -28,7 +28,7 @@ import java.util.Map; -import static io.microsphere.spring.util.PropertySourcesUtils.getSubProperties; +import static io.microsphere.spring.core.env.PropertySourcesUtils.getSubProperties; import static org.junit.jupiter.api.Assertions.assertEquals; /** diff --git a/microsphere-core-spring-boot-starter/src/test/resources/logback.xml b/microsphere-core-spring-boot-starter/src/test/resources/logback.xml index 15fd317..fbbd2bd 100644 --- a/microsphere-core-spring-boot-starter/src/test/resources/logback.xml +++ b/microsphere-core-spring-boot-starter/src/test/resources/logback.xml @@ -1,4 +1,4 @@ - + diff --git a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/env/DefaultPropertiesTest.java b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/env/DefaultPropertiesTest.java index 175ba78..8b38131 100644 --- a/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/env/DefaultPropertiesTest.java +++ b/microsphere-spring-boot-actuator/src/test/java/io/microsphere/spring/boot/actuate/env/DefaultPropertiesTest.java @@ -57,7 +57,7 @@ public void testEndpointsDefaultProperties() { assertProperty("management.endpoint.httptrace.enabled", "false"); assertProperty("management.endpoint.info.enabled", "true"); assertProperty("management.endpoint.integrationgraph.enabled", "false"); - assertProperty("management.endpoint.loggers.enabled", "true"); + assertProperty("management.endpoint.loggers.enabled", "false"); assertProperty("management.endpoint.liquibase.enabled", "false"); assertProperty("management.endpoint.metrics.enabled", "true"); assertProperty("management.endpoint.mappings.enabled", "true"); @@ -74,6 +74,6 @@ public void testEndpointsDefaultProperties() { } private void assertProperty(String propertyName, String expectedValue) { - assertEquals(environment.getRequiredProperty(propertyName), expectedValue); + assertEquals(expectedValue, environment.getRequiredProperty(propertyName)); } } diff --git a/microsphere-spring-boot-parent/pom.xml b/microsphere-spring-boot-parent/pom.xml index 74e13a0..3de6c06 100644 --- a/microsphere-spring-boot-parent/pom.xml +++ b/microsphere-spring-boot-parent/pom.xml @@ -19,7 +19,7 @@ Microsphere Spring Boot Parent - 2.0.0-SNAPSHOT + 0.2.0 1.7.2 diff --git a/pom.xml b/pom.xml index 2bed7fa..4f47016 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.github.microsphere-projects microsphere-build - 0.0.21 + 0.1.1 4.0.0 From 250c252cdec836758b2579d35a604a9e7c06dfc3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 17:26:57 +0800 Subject: [PATCH 46/51] Polish #16 --- .../classloading/BannedArtifactClassLoadingListener.java | 7 ++++--- .../boot/context/OnceApplicationPreparedEventListener.java | 7 ++++--- ...ConfigurationPropertiesBeanPropertyChangedListener.java | 6 +++--- .../properties/metadata/ConfigurationMetadataReader.java | 6 +++--- .../boot/env/DefaultPropertiesApplicationListener.java | 6 +++--- .../OriginTrackedConfigurationPropertyInitializer.java | 4 ++-- .../autoconfigure/ApplicationAutoConfigurationTest.java | 1 - ...nableConfigurationPropertiesBindHandlerAdvisorTest.java | 7 ++++--- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/classloading/BannedArtifactClassLoadingListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/classloading/BannedArtifactClassLoadingListener.java index 59ac68d..78ab99e 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/classloading/BannedArtifactClassLoadingListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/classloading/BannedArtifactClassLoadingListener.java @@ -1,9 +1,8 @@ package io.microsphere.spring.boot.classloading; import io.microsphere.classloading.BannedArtifactClassLoadingExecutor; +import io.microsphere.logging.Logger; import io.microsphere.spring.boot.listener.SpringApplicationRunListenerAdapter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.context.ApplicationListener; @@ -12,6 +11,8 @@ import java.util.Arrays; +import static io.microsphere.logging.LoggerFactory.getLogger; + /** * {@link ApplicationStartingEvent ApplicationStartingEvent} {@link ApplicationListener Listener} bans * the load of Artifacts collision class @@ -21,7 +22,7 @@ */ public class BannedArtifactClassLoadingListener extends SpringApplicationRunListenerAdapter implements Ordered { - private static final Logger logger = LoggerFactory.getLogger(BannedArtifactClassLoadingListener.class); + private static final Logger logger = getLogger(BannedArtifactClassLoadingListener.class); private static final boolean artifactsBanned = Boolean.getBoolean("microsphere.artifacts.banned"); diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceApplicationPreparedEventListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceApplicationPreparedEventListener.java index 96c1879..7865d81 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceApplicationPreparedEventListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceApplicationPreparedEventListener.java @@ -1,7 +1,6 @@ package io.microsphere.spring.boot.context; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.microsphere.logging.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.context.ApplicationListener; @@ -13,6 +12,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; +import static io.microsphere.logging.LoggerFactory.getLogger; + /** * Once execution {@link ApplicationPreparedEvent} {@link ApplicationListener} * @@ -24,7 +25,7 @@ public abstract class OnceApplicationPreparedEventListener implements Applicatio private static Map, Set> listenerProcessedContextIds = new ConcurrentHashMap<>(); - protected final Logger logger = LoggerFactory.getLogger(getClass()); + protected final Logger logger = getLogger(getClass()); private final Set processedContextIds; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java index 6a44c56..59db6c2 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/EventPublishingConfigurationPropertiesBeanPropertyChangedListener.java @@ -16,8 +16,7 @@ */ package io.microsphere.spring.boot.context.properties.bind; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.microsphere.logging.Logger; import org.springframework.beans.BeansException; import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -35,6 +34,7 @@ import java.util.Map; import java.util.function.Supplier; +import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.spring.boot.context.properties.bind.util.BindUtils.isBoundProperty; import static io.microsphere.spring.boot.context.properties.bind.util.BindUtils.isConfigurationPropertiesBean; import static io.microsphere.spring.boot.context.properties.source.util.ConfigurationPropertyUtils.getPrefix; @@ -54,7 +54,7 @@ */ public class EventPublishingConfigurationPropertiesBeanPropertyChangedListener implements BindListener, BeanFactoryPostProcessor, ApplicationContextAware, SmartInitializingSingleton { - private final static Logger logger = LoggerFactory.getLogger(EventPublishingConfigurationPropertiesBeanPropertyChangedListener.class); + private final static Logger logger = getLogger(EventPublishingConfigurationPropertiesBeanPropertyChangedListener.class); private static final Class CONFIGURABLE_APPLICATION_CONTEXT_CLASS = ConfigurableApplicationContext.class; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/metadata/ConfigurationMetadataReader.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/metadata/ConfigurationMetadataReader.java index f25208a..b80aac6 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/metadata/ConfigurationMetadataReader.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/metadata/ConfigurationMetadataReader.java @@ -16,8 +16,7 @@ */ package io.microsphere.spring.boot.context.properties.metadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.microsphere.logging.Logger; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller; import org.springframework.context.ResourceLoaderAware; @@ -28,6 +27,7 @@ import java.io.IOException; +import static io.microsphere.logging.LoggerFactory.getLogger; import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX; /** @@ -38,7 +38,7 @@ */ public class ConfigurationMetadataReader implements ResourceLoaderAware { - private final static Logger logger = LoggerFactory.getLogger(ConfigurationMetadataReader.class); + private final static Logger logger = getLogger(ConfigurationMetadataReader.class); public static final String METADATA_PATH = CLASSPATH_ALL_URL_PREFIX + "/META-INF/spring-configuration-metadata.json"; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java index debd8ac..5a4b774 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java @@ -1,7 +1,6 @@ package io.microsphere.spring.boot.env; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.microsphere.logging.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.logging.LoggingApplicationListener; @@ -25,6 +24,7 @@ import java.util.Properties; import java.util.Set; +import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.spring.boot.util.SpringApplicationUtils.getDefaultPropertiesResources; import static io.microsphere.spring.boot.util.SpringApplicationUtils.getResourceLoader; import static io.microsphere.spring.core.env.PropertySourcesUtils.getDefaultProperties; @@ -44,7 +44,7 @@ public class DefaultPropertiesApplicationListener implements ApplicationListener public static final int DEFAULT_ORDER = LoggingApplicationListener.LOWEST_PRECEDENCE - 1; - private static final Logger logger = LoggerFactory.getLogger(DefaultPropertiesApplicationListener.class); + private static final Logger logger = getLogger(DefaultPropertiesApplicationListener.class); private int order = DEFAULT_ORDER; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java index 5fdfaa0..f179b4e 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/config/OriginTrackedConfigurationPropertyInitializer.java @@ -17,7 +17,6 @@ package io.microsphere.spring.boot.env.config; import io.microsphere.logging.Logger; -import io.microsphere.logging.LoggerFactory; import io.microsphere.spring.boot.env.PropertySourceLoaders; import io.microsphere.spring.context.event.BeanFactoryListenerAdapter; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -38,6 +37,7 @@ import java.util.LinkedHashMap; import java.util.Map; +import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.spring.beans.factory.support.BeanRegistrar.registerBean; /** @@ -51,7 +51,7 @@ public class OriginTrackedConfigurationPropertyInitializer implements BeanFactor public static final String BEAN_NAME = "originTrackedConfigurationPropertyInitializer"; - private static final Logger logger = LoggerFactory.getLogger(OriginTrackedConfigurationPropertyInitializer.class); + private static final Logger logger = getLogger(OriginTrackedConfigurationPropertyInitializer.class); private ConfigurableApplicationContext applicationContext; diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java index 5a3702e..66093b8 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/autoconfigure/ApplicationAutoConfigurationTest.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/properties/ListenableConfigurationPropertiesBindHandlerAdvisorTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/properties/ListenableConfigurationPropertiesBindHandlerAdvisorTest.java index 328c753..24faedb 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/properties/ListenableConfigurationPropertiesBindHandlerAdvisorTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/properties/ListenableConfigurationPropertiesBindHandlerAdvisorTest.java @@ -16,10 +16,9 @@ */ package io.microsphere.spring.boot.context.properties; +import io.microsphere.logging.Logger; import io.microsphere.spring.boot.context.properties.bind.BindListener; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.bind.BindContext; @@ -29,6 +28,8 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; +import static io.microsphere.logging.LoggerFactory.getLogger; + /** * {@link ListenableConfigurationPropertiesBindHandlerAdvisor} Test * @@ -50,7 +51,7 @@ @EnableConfigurationProperties public class ListenableConfigurationPropertiesBindHandlerAdvisorTest { - private static final Logger logger = LoggerFactory.getLogger(ListenableConfigurationPropertiesBindHandlerAdvisorTest.class); + private static final Logger logger = getLogger(ListenableConfigurationPropertiesBindHandlerAdvisorTest.class); @Test public void test() { From 2a32b198e7f1c349b3f76cdbf62b5ee4a65e50b3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 17:29:59 +0800 Subject: [PATCH 47/51] Polish #18 --- .github/workflows/maven-build.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index f95530a..188ab21 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -39,6 +39,11 @@ jobs: --update-snapshots --file pom.xml -Drevision=0.0.1-SNAPSHOT - -DargLine="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED" - -P${{ matrix.maven-profile-spring-boot }} - test \ No newline at end of file + test + --activate-profiles test,coverage,${{ matrix.maven-profile-spring-boot }} + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: microsphere-projects/microsphere-spring-boot \ No newline at end of file From d1995f0cdb9931e0976716fd095efebfa9101318 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 17:39:11 +0800 Subject: [PATCH 48/51] Polish #19 --- .github/workflows/maven-build.yml | 4 +-- microsphere-spring-boot-parent/pom.xml | 39 ++++++-------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 188ab21..cc327f3 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -20,8 +20,8 @@ jobs: strategy: matrix: java: [ '17' , '21' ] - maven-profile-spring-boot: [ 'spring-boot-2.4' , 'spring-boot-2.5' , 'spring-boot-2.6' , 'spring-boot-2.7' , - 'spring-boot-3.0' , 'spring-boot-3.1' , 'spring-boot-3.2' , 'spring-boot-3.3' ] + maven-profile-spring-boot: [ 'spring-boot-3.0' , 'spring-boot-3.1' , 'spring-boot-3.2' , + 'spring-boot-3.3' , 'spring-boot-3.4' ] steps: - name: Checkout Source uses: actions/checkout@v4 diff --git a/microsphere-spring-boot-parent/pom.xml b/microsphere-spring-boot-parent/pom.xml index 3de6c06..9e7756c 100644 --- a/microsphere-spring-boot-parent/pom.xml +++ b/microsphere-spring-boot-parent/pom.xml @@ -46,34 +46,6 @@ - - spring-boot-2.4 - - 2.4.13 - - - - - spring-boot-2.5 - - 2.5.15 - - - - - spring-boot-2.6 - - 2.6.15 - - - - - spring-boot-2.7 - - 2.7.18 - - - spring-boot-3.0 @@ -91,17 +63,24 @@ spring-boot-3.2 - 3.2.7 + 3.2.12 spring-boot-3.3 + + 3.3.7 + + + + + spring-boot-3.4 true - 3.3.1 + 3.4.1 From c1651b7b7db650b7b879def5fabceb4c1d2dd2e8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 18:59:55 +0800 Subject: [PATCH 49/51] Remove ParallelPreInstantiationSingletonsBeanFactoryListener --- .../src/test/resources/META-INF/spring.factories | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories b/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories index c4d0955..a60dc2e 100644 --- a/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories +++ b/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories @@ -9,5 +9,5 @@ io.microsphere.spring.context.event.BeanTimeStatistics # BeanFactoryListener io.microsphere.spring.context.event.BeanFactoryListener=\ -io.microsphere.spring.context.event.LoggingBeanFactoryListener,\ -io.microsphere.spring.context.event.ParallelPreInstantiationSingletonsBeanFactoryListener \ No newline at end of file +io.microsphere.spring.context.event.LoggingBeanFactoryListener +# io.microsphere.spring.context.event.ParallelPreInstantiationSingletonsBeanFactoryListener \ No newline at end of file From 952ab30dd1ba13c9da796e2c6466a18c1c2606e3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Wed, 8 Jan 2025 19:16:23 +0800 Subject: [PATCH 50/51] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b23389..c7b0801 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # microsphere-spring-boot -Microsphere Projects for Spring Boot +> Microsphere Projects for Spring Boot + +[![Maven Build](https://github.com/microsphere-projects/microsphere-spring-boot/actions/workflows/maven-build.yml/badge.svg)](https://github.com/microsphere-projects/microsphere-spring-boot/actions/workflows/maven-build.yml) +[![Codecov](https://codecov.io/gh/microsphere-projects/microsphere-spring-boot/branch/dev/graph/badge.svg)](https://app.codecov.io/gh/microsphere-projects/microsphere-spring-boot) +![Maven](https://img.shields.io/maven-central/v/io.github.microsphere-projects/microsphere-spring-boot.svg) +![License](https://img.shields.io/github/license/microsphere-projects/microsphere-spring-boot.svg) +[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/microsphere-projects/microsphere-spring-boot.svg)](http://isitmaintained.com/project/microsphere-projects/microsphere-spring-boot "Average time to resolve an issue") +[![Percentage of issues still open](http://isitmaintained.com/badge/open/microsphere-projects/microsphere-spring-boot.svg)](http://isitmaintained.com/project/microsphere-projects/microsphere-spring-boot "Percentage of issues still open") From 0992320c5bca298d78fad78e35e3776f83676e56 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 9 Jan 2025 10:54:56 +0800 Subject: [PATCH 51/51] Sync dev-1.x branch code --- .gitignore | 3 +++ microsphere-core-spring-boot-starter/pom.xml | 6 ++++++ .../context/OnceMainApplicationPreparedEventListener.java | 4 ++-- .../bind/ConfigurationPropertiesBeanContext.java | 8 ++++---- .../boot/env/DefaultPropertiesApplicationListener.java | 6 +++--- .../boot/report/ConditionsReportMessageBuilder.java | 5 +++-- .../spring/boot/util/SpringApplicationUtils.java | 5 +++-- .../config/BindableConfigurationBeanBinderTest.java | 3 ++- .../src/test/resources/META-INF/spring.factories | 3 +-- microsphere-spring-boot-actuator/pom.xml | 6 ++++++ .../boot/actuate/MonitoredThreadPoolTaskScheduler.java | 3 +-- 11 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 9203168..e551b45 100644 --- a/.gitignore +++ b/.gitignore @@ -65,5 +65,8 @@ compiler/.gradle/* .extract .java-version +# vscode +.vscode/ + # others build.txt \ No newline at end of file diff --git a/microsphere-core-spring-boot-starter/pom.xml b/microsphere-core-spring-boot-starter/pom.xml index cb0af68..1acaa52 100644 --- a/microsphere-core-spring-boot-starter/pom.xml +++ b/microsphere-core-spring-boot-starter/pom.xml @@ -43,6 +43,12 @@ + + org.junit.jupiter + junit-jupiter + test + + org.springframework.boot spring-boot-starter-test diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceMainApplicationPreparedEventListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceMainApplicationPreparedEventListener.java index 3974cf7..a94ff33 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceMainApplicationPreparedEventListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/OnceMainApplicationPreparedEventListener.java @@ -6,11 +6,11 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; -import org.springframework.util.ClassUtils; import java.util.List; import static java.util.Arrays.asList; +import static org.springframework.util.ClassUtils.isPresent; /** @@ -25,7 +25,7 @@ public abstract class OnceMainApplicationPreparedEventListener extends OnceAppli private static final String BOOTSTRAP_APPLICATION_LISTENER_ENABLED_PROPERTY_NAME = "spring.cloud.bootstrap.enabled"; - private static final boolean BOOTSTRAP_APPLICATION_LISTENER_PRESENT = ClassUtils.isPresent(BOOTSTRAP_APPLICATION_LISTENER_CLASS_NAME, null); + private static final boolean BOOTSTRAP_APPLICATION_LISTENER_PRESENT = isPresent(BOOTSTRAP_APPLICATION_LISTENER_CLASS_NAME, null); private static final String BOOTSTRAP_CONTEXT_ID = "bootstrap"; diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContext.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContext.java index d9959cb..4d98edf 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContext.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/context/properties/bind/ConfigurationPropertiesBeanContext.java @@ -17,14 +17,12 @@ package io.microsphere.spring.boot.context.properties.bind; import io.microsphere.spring.core.convert.support.ConversionServiceResolver; -import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapperImpl; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.source.ConfigurationProperty; import org.springframework.boot.context.properties.source.ConfigurationPropertyName; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.convert.ConversionService; -import org.springframework.util.ClassUtils; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; @@ -34,6 +32,8 @@ import static io.microsphere.spring.boot.context.properties.source.util.ConfigurationPropertyUtils.toDashedForm; import static org.springframework.beans.BeanUtils.copyProperties; +import static org.springframework.beans.BeanUtils.getPropertyDescriptors; +import static org.springframework.util.ClassUtils.isPrimitiveOrWrapper; /** * The context for the bean annotated {@link ConfigurationProperties @ConfigurationProperties} @@ -95,7 +95,7 @@ private void initBinding(Object bean) { private void initBinding(Class beanClass, String prefix, Map bindingPropertyNames, String nestedPath) { if (isCandidateClass(beanClass)) { - PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(beanClass); + PropertyDescriptor[] descriptors = getPropertyDescriptors(beanClass); int descriptorSize = descriptors.length; for (int i = 0; i < descriptorSize; i++) { PropertyDescriptor descriptor = descriptors[i]; @@ -117,7 +117,7 @@ private boolean isCandidateProperty(PropertyDescriptor descriptor) { } private boolean isCandidateClass(Class beanClass) { - if (ClassUtils.isPrimitiveOrWrapper(beanClass)) { + if (isPrimitiveOrWrapper(beanClass)) { return false; } if (beanClass.isInterface() || beanClass.isEnum() || beanClass.isAnnotation() || beanClass.isArray() || beanClass.isSynthetic()) { diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java index 5a4b774..87584a0 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/env/DefaultPropertiesApplicationListener.java @@ -13,7 +13,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.util.ObjectUtils; import java.io.IOException; import java.net.URL; @@ -30,6 +29,7 @@ import static io.microsphere.spring.core.env.PropertySourcesUtils.getDefaultProperties; import static io.microsphere.spring.core.io.ResourceLoaderUtils.getResourcePatternResolver; import static org.springframework.core.io.support.SpringFactoriesLoader.loadFactories; +import static org.springframework.util.ObjectUtils.containsElement; /** * Listable {@link ApplicationEnvironmentPreparedEvent} {@link ApplicationListener} Class @@ -81,7 +81,7 @@ private void loadDefaultPropertiesResources(List propertyS ResourceLoader resourceLoader, Map defaultProperties) { Set defaultPropertiesResources = getDefaultPropertiesResources(); - logger.debug("Start loading from SpringApplicationUtils. GetDefaultPropertiesResources () 'defaultProperties resources: {}", defaultPropertiesResources); + logger.debug("Start loading from SpringApplicationUtils.loadDefaultPropertiesResources() 'defaultProperties resources: {}", defaultPropertiesResources); loadDefaultProperties(defaultPropertiesResources, propertySourceLoaders, resourceLoader, defaultProperties); } @@ -178,7 +178,7 @@ private void merge(EnumerablePropertySource propertySource, Map getBasePackages(ConfigurableApplicationContext context) { } private void appendLine(StringBuilder stringBuilder, String text, Object... args) { - stringBuilder.append(FormatUtils.format(text, args)).append(System.lineSeparator()); + stringBuilder.append(format(text, args)).append(System.lineSeparator()); } } diff --git a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/util/SpringApplicationUtils.java b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/util/SpringApplicationUtils.java index ca9d8f5..6e93f34 100644 --- a/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/util/SpringApplicationUtils.java +++ b/microsphere-core-spring-boot-starter/src/main/java/io/microsphere/spring/boot/util/SpringApplicationUtils.java @@ -3,12 +3,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; -import org.springframework.util.StringUtils; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static org.springframework.util.StringUtils.hasText; + /** * {@link SpringApplication} Utilities class * @@ -29,7 +30,7 @@ private SpringApplicationUtils() throws InstantiationException { * @param resourceLocation "defaultProperties" resource path */ public static void addDefaultPropertiesResource(String resourceLocation) { - if (StringUtils.hasText(resourceLocation)) { + if (hasText(resourceLocation)) { defaultPropertiesResources.add(resourceLocation); } } diff --git a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java index 3eac07e..dbb82f2 100644 --- a/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java +++ b/microsphere-core-spring-boot-starter/src/test/java/io/microsphere/spring/boot/context/config/BindableConfigurationBeanBinderTest.java @@ -29,6 +29,7 @@ import java.util.Map; import static io.microsphere.spring.core.env.PropertySourcesUtils.getSubProperties; +import static java.lang.Integer.valueOf; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -59,6 +60,6 @@ void testBind() { Map properties = getSubProperties(environment.getPropertySources(), "user"); beanBinder.bind(properties, true, true, user); assertEquals("mercyblitz", user.getName()); - assertEquals(37, user.getAge()); + assertEquals(valueOf(37), user.getAge()); } } diff --git a/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories b/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories index a60dc2e..3e82d88 100644 --- a/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories +++ b/microsphere-core-spring-boot-starter/src/test/resources/META-INF/spring.factories @@ -9,5 +9,4 @@ io.microsphere.spring.context.event.BeanTimeStatistics # BeanFactoryListener io.microsphere.spring.context.event.BeanFactoryListener=\ -io.microsphere.spring.context.event.LoggingBeanFactoryListener -# io.microsphere.spring.context.event.ParallelPreInstantiationSingletonsBeanFactoryListener \ No newline at end of file +io.microsphere.spring.context.event.LoggingBeanFactoryListener \ No newline at end of file diff --git a/microsphere-spring-boot-actuator/pom.xml b/microsphere-spring-boot-actuator/pom.xml index ca4da0f..3391a58 100644 --- a/microsphere-spring-boot-actuator/pom.xml +++ b/microsphere-spring-boot-actuator/pom.xml @@ -60,6 +60,12 @@ + + org.junit.jupiter + junit-jupiter + test + + org.springframework.boot spring-boot-starter-test diff --git a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/MonitoredThreadPoolTaskScheduler.java b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/MonitoredThreadPoolTaskScheduler.java index 77af057..08064f7 100644 --- a/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/MonitoredThreadPoolTaskScheduler.java +++ b/microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/MonitoredThreadPoolTaskScheduler.java @@ -18,7 +18,6 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; -import io.micrometer.core.instrument.internal.TimedScheduledExecutorService; import io.microsphere.concurrent.DelegatingScheduledExecutorService; import org.springframework.beans.BeansException; import org.springframework.beans.factory.SmartInitializingSingleton; @@ -38,7 +37,7 @@ * @author Mercy * @see ThreadPoolTaskScheduler * @see ExecutorServiceMetrics - * @see TimedScheduledExecutorService + * @see io.micrometer.core.instrument.internal.TimedScheduledExecutorService * @since 1.0.0 */ public class MonitoredThreadPoolTaskScheduler extends ThreadPoolTaskScheduler implements ApplicationContextAware, SmartInitializingSingleton {