Skip to content

Commit de5ba80

Browse files
committed
fix: native support for retry template factory
1 parent c322f38 commit de5ba80

File tree

3 files changed

+83
-34
lines changed

3 files changed

+83
-34
lines changed

spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigClientAutoConfiguration.java

-33
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,19 @@
1616

1717
package org.springframework.cloud.config.client;
1818

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;
2319
import org.springframework.beans.factory.BeanFactoryUtils;
2420
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
2521
import org.springframework.boot.actuate.health.HealthIndicator;
2622
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2723
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2824
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2925
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
30-
import org.springframework.boot.context.config.ConfigDataLocation;
31-
import org.springframework.cloud.config.environment.PropertySource;
3226
import org.springframework.cloud.context.refresh.ContextRefresher;
3327
import org.springframework.context.ApplicationContext;
3428
import org.springframework.context.annotation.Bean;
3529
import org.springframework.context.annotation.Configuration;
3630
import org.springframework.core.env.ConfigurableEnvironment;
3731
import org.springframework.core.env.Environment;
38-
import org.springframework.util.ClassUtils;
3932

4033
/**
4134
* Expose a ConfigClientProperties just so that there is a way to inspect the properties
@@ -93,29 +86,3 @@ public ConfigClientWatch configClientWatch(ContextRefresher contextRefresher) {
9386
}
9487

9588
}
96-
97-
class ConfigClientHints implements RuntimeHintsRegistrar {
98-
99-
@Override
100-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
101-
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerConfigDataLoader",
102-
classLoader)) {
103-
return;
104-
}
105-
hints.reflection()
106-
.registerType(TypeReference.of(ConfigClientAutoConfiguration.class),
107-
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
108-
.registerType(TypeReference.of(ConfigDataLocation.class),
109-
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS))
110-
.registerType(TypeReference.of("org.springframework.boot.context.config.ConfigDataProperties"),
111-
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
112-
MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_DECLARED_METHODS))
113-
.registerType(TypeReference.of(org.springframework.cloud.config.environment.Environment.class),
114-
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
115-
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS))
116-
.registerType(TypeReference.of(PropertySource.class),
117-
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
118-
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
119-
}
120-
121-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2-
org.springframework.cloud.config.client.ConfigClientHints
2+
org.springframework.cloud.config.client.aot.ConfigClientHints

0 commit comments

Comments
 (0)