diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientAutoConfiguration.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientAutoConfiguration.java index a86efc1d98..8accdd1d18 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientAutoConfiguration.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientAutoConfiguration.java @@ -16,10 +16,6 @@ package org.springframework.cloud.config.client; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeReference; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator; @@ -27,15 +23,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.config.ConfigDataLocation; -import org.springframework.cloud.config.environment.PropertySource; import org.springframework.cloud.context.refresh.ContextRefresher; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; -import org.springframework.util.ClassUtils; /** * Expose a ConfigClientProperties just so that there is a way to inspect the properties @@ -93,29 +86,3 @@ public ConfigClientWatch configClientWatch(ContextRefresher contextRefresher) { } } - -class ConfigClientHints implements RuntimeHintsRegistrar { - - @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerConfigDataLoader", - classLoader)) { - return; - } - hints.reflection() - .registerType(TypeReference.of(ConfigClientAutoConfiguration.class), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)) - .registerType(TypeReference.of(ConfigDataLocation.class), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS)) - .registerType(TypeReference.of("org.springframework.boot.context.config.ConfigDataProperties"), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, - MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_DECLARED_METHODS)) - .registerType(TypeReference.of(org.springframework.cloud.config.environment.Environment.class), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, - MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)) - .registerType(TypeReference.of(PropertySource.class), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, - MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)); - } - -} diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/aot/ConfigClientHints.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/aot/ConfigClientHints.java new file mode 100644 index 0000000000..e025ab0d42 --- /dev/null +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/aot/ConfigClientHints.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013-2024 the original author or authors. + * + * Licensed 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 + * + * https://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 org.springframework.cloud.config.client.aot; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; +import org.springframework.boot.context.config.ConfigDataLocation; +import org.springframework.cloud.config.client.ConfigClientAutoConfiguration; +import org.springframework.cloud.config.client.RetryTemplateFactory; +import org.springframework.cloud.config.environment.Environment; +import org.springframework.cloud.config.environment.PropertySource; +import org.springframework.util.ClassUtils; + +/** + * The config client runtime hints to enable the client to be used for aot builds. + * + * @author Olga Maciaszek-Sharma + * @author Tobias Soloschenko + */ +class ConfigClientHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerConfigDataLoader", + classLoader)) { + return; + } + hints.reflection() + .registerType(TypeReference.of(ConfigClientAutoConfiguration.class), + hint -> hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS) + ).registerType(TypeReference.of(ConfigDataLocation.class), + hint -> hint.withMembers( + MemberCategory.INVOKE_DECLARED_METHODS) + ).registerType(TypeReference.of("org.springframework.boot.context.config.ConfigDataProperties"), + hint -> hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.DECLARED_FIELDS, + MemberCategory.INTROSPECT_DECLARED_METHODS) + ).registerType(TypeReference.of(Environment.class), + hint -> hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INTROSPECT_DECLARED_METHODS, + MemberCategory.DECLARED_FIELDS) + ).registerType(TypeReference.of(PropertySource.class), + hint -> hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INTROSPECT_DECLARED_METHODS, + MemberCategory.DECLARED_FIELDS) + ).registerType(TypeReference.of(RetryTemplateFactory.class), + hint -> hint.withMembers( + MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.DECLARED_FIELDS, + MemberCategory.INTROSPECT_DECLARED_METHODS, + MemberCategory.INVOKE_DECLARED_METHODS) + ); + } +} diff --git a/spring-cloud-config-client/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-config-client/src/main/resources/META-INF/spring/aot.factories index b4ad6c7e31..2aca90752a 100644 --- a/spring-cloud-config-client/src/main/resources/META-INF/spring/aot.factories +++ b/spring-cloud-config-client/src/main/resources/META-INF/spring/aot.factories @@ -1,2 +1,2 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\ -org.springframework.cloud.config.client.ConfigClientHints +org.springframework.cloud.config.client.aot.ConfigClientHints