|
| 1 | +/* |
| 2 | + * Copyright 2013-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.cloud.config.client.aot; |
| 18 | + |
| 19 | +import org.springframework.aot.hint.MemberCategory; |
| 20 | +import org.springframework.aot.hint.RuntimeHints; |
| 21 | +import org.springframework.aot.hint.RuntimeHintsRegistrar; |
| 22 | +import org.springframework.aot.hint.TypeReference; |
| 23 | +import org.springframework.boot.context.config.ConfigDataLocation; |
| 24 | +import org.springframework.cloud.config.client.ConfigClientAutoConfiguration; |
| 25 | +import org.springframework.cloud.config.client.RetryTemplateFactory; |
| 26 | +import org.springframework.cloud.config.environment.Environment; |
| 27 | +import org.springframework.cloud.config.environment.PropertySource; |
| 28 | +import org.springframework.retry.support.RetryTemplate; |
| 29 | +import org.springframework.util.ClassUtils; |
| 30 | + |
| 31 | +/** |
| 32 | + * The config client runtime hints to enable the client to be used for aot builds. |
| 33 | + * |
| 34 | + * @author Olga Maciaszek-Sharma |
| 35 | + * @author Tobias Soloschenko |
| 36 | + */ |
| 37 | +class ConfigClientHints implements RuntimeHintsRegistrar { |
| 38 | + |
| 39 | + @Override |
| 40 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 41 | + if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerConfigDataLoader", |
| 42 | + classLoader)) { |
| 43 | + return; |
| 44 | + } |
| 45 | + hints.reflection() |
| 46 | + .registerType(TypeReference.of(ConfigClientAutoConfiguration.class), |
| 47 | + hint -> hint.withMembers( |
| 48 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS) |
| 49 | + ).registerType(TypeReference.of(ConfigDataLocation.class), |
| 50 | + hint -> hint.withMembers( |
| 51 | + MemberCategory.INVOKE_DECLARED_METHODS) |
| 52 | + ).registerType(TypeReference.of("org.springframework.boot.context.config.ConfigDataProperties"), |
| 53 | + hint -> hint.withMembers( |
| 54 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 55 | + MemberCategory.DECLARED_FIELDS, |
| 56 | + MemberCategory.INTROSPECT_DECLARED_METHODS) |
| 57 | + ).registerType(TypeReference.of(Environment.class), |
| 58 | + hint -> hint.withMembers( |
| 59 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 60 | + MemberCategory.INTROSPECT_DECLARED_METHODS, |
| 61 | + MemberCategory.DECLARED_FIELDS) |
| 62 | + ).registerType(TypeReference.of(PropertySource.class), |
| 63 | + hint -> hint.withMembers( |
| 64 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 65 | + MemberCategory.INTROSPECT_DECLARED_METHODS, |
| 66 | + MemberCategory.DECLARED_FIELDS) |
| 67 | + ).registerType(TypeReference.of(RetryTemplateFactory.class), |
| 68 | + hint -> hint.withMembers( |
| 69 | + MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, |
| 70 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 71 | + MemberCategory.DECLARED_FIELDS, |
| 72 | + MemberCategory.INTROSPECT_DECLARED_METHODS, |
| 73 | + MemberCategory.INVOKE_DECLARED_METHODS) |
| 74 | + ).registerType(TypeReference.of(RetryTemplate.class), |
| 75 | + hint -> hint.withMembers( |
| 76 | + MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, |
| 77 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, |
| 78 | + MemberCategory.INTROSPECT_DECLARED_METHODS, |
| 79 | + MemberCategory.INVOKE_DECLARED_METHODS) |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments