Skip to content

Commit 975e421

Browse files
authored
Feature/native runtime hints (#2450)
Moved RuntimeHints for spring native builds to client and server autoconfigurations.
1 parent 28273bd commit 975e421

File tree

7 files changed

+135
-39
lines changed

7 files changed

+135
-39
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2014-2018 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 de.codecentric.boot.admin.client.config;
18+
19+
import lombok.SneakyThrows;
20+
import org.springframework.aot.hint.ExecutableMode;
21+
import org.springframework.aot.hint.MemberCategory;
22+
import org.springframework.aot.hint.RuntimeHints;
23+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
24+
import org.springframework.context.annotation.Configuration;
25+
26+
import de.codecentric.boot.admin.client.registration.Application;
27+
28+
@Configuration
29+
public class ClientRuntimeHints implements RuntimeHintsRegistrar {
30+
31+
@Override
32+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
33+
registerReflectionHints(hints);
34+
}
35+
36+
@SneakyThrows
37+
private static void registerReflectionHints(RuntimeHints hints) {
38+
hints.reflection()
39+
.registerType(Application.Builder.class, MemberCategory.INVOKE_PUBLIC_METHODS,
40+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
41+
.registerType(Application.class, MemberCategory.INVOKE_PUBLIC_METHODS,
42+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
43+
.registerConstructor(Application.Builder.class.getDeclaredConstructor(), ExecutableMode.INVOKE)
44+
.registerMethod(Application.Builder.class.getMethod("build"), ExecutableMode.INVOKE)
45+
.registerMethod(Application.class.getMethod("builder"), ExecutableMode.INVOKE);
46+
}
47+
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014-2018 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 de.codecentric.boot.admin.client.config;
18+
19+
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
20+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
22+
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
23+
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration;
24+
import org.springframework.context.annotation.Conditional;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.annotation.ImportRuntimeHints;
27+
28+
@Configuration(proxyBeanMethods = false)
29+
@ConditionalOnWebApplication
30+
@Conditional(SpringBootAdminClientEnabledCondition.class)
31+
@AutoConfigureAfter({ WebEndpointAutoConfiguration.class, RestTemplateAutoConfiguration.class,
32+
WebClientAutoConfiguration.class })
33+
@ImportRuntimeHints({ ClientRuntimeHints.class })
34+
public class SpringNativeClientAutoConfiguration {
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration
22
de.codecentric.boot.admin.client.config.SpringBootAdminClientCloudFoundryAutoConfiguration
3+
de.codecentric.boot.admin.client.config.SpringNativeClientAutoConfiguration

spring-boot-admin-samples/spring-boot-admin-sample-servlet-graalvm/src/main/java/de/codecentric/boot/admin/SpringBootAdminServletApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2121
import org.springframework.context.annotation.Configuration;
22-
import org.springframework.context.annotation.ImportRuntimeHints;
2322

2423
import de.codecentric.boot.admin.server.config.EnableAdminServer;
2524

2625
@Configuration(proxyBeanMethods = false)
2726
@EnableAutoConfiguration
2827
@EnableAdminServer
29-
@ImportRuntimeHints({ RuntimeHints.class })
3028
public class SpringBootAdminServletApplication {
3129

3230
public static void main(String[] args) {
Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package de.codecentric.boot.admin;
17+
package de.codecentric.boot.admin.server.ui.config;
1818

1919
import java.util.ArrayList;
2020
import java.util.HashMap;
2121
import java.util.Map;
22-
import java.util.Set;
2322

2423
import com.fasterxml.jackson.databind.ser.std.ClassSerializer;
2524
import com.fasterxml.jackson.databind.ser.std.FileSerializer;
@@ -28,12 +27,12 @@
2827
import lombok.SneakyThrows;
2928
import org.springframework.aot.hint.ExecutableMode;
3029
import org.springframework.aot.hint.MemberCategory;
30+
import org.springframework.aot.hint.RuntimeHints;
3131
import org.springframework.aot.hint.RuntimeHintsRegistrar;
3232
import org.springframework.aot.hint.TypeHint;
3333
import org.springframework.aot.hint.TypeReference;
3434
import org.springframework.context.annotation.Configuration;
3535

36-
import de.codecentric.boot.admin.client.registration.Application;
3736
import de.codecentric.boot.admin.server.domain.entities.Instance;
3837
import de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent;
3938
import de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent;
@@ -50,8 +49,6 @@
5049
import de.codecentric.boot.admin.server.domain.values.Registration;
5150
import de.codecentric.boot.admin.server.domain.values.StatusInfo;
5251
import de.codecentric.boot.admin.server.domain.values.Tags;
53-
import de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties;
54-
import de.codecentric.boot.admin.server.ui.config.CssColorUtils;
5552
import de.codecentric.boot.admin.server.ui.web.UiController;
5653
import de.codecentric.boot.admin.server.utils.jackson.BuildVersionMixin;
5754
import de.codecentric.boot.admin.server.utils.jackson.EndpointMixin;
@@ -69,21 +66,19 @@
6966
import de.codecentric.boot.admin.server.utils.jackson.TagsMixin;
7067
import de.codecentric.boot.admin.server.web.InstanceWebProxy;
7168

72-
import static org.springframework.util.ReflectionUtils.findMethod;
73-
7469
@Configuration
75-
public class RuntimeHints implements RuntimeHintsRegistrar {
70+
public class ServerRuntimeHints implements RuntimeHintsRegistrar {
7671

7772
@Override
78-
public void registerHints(org.springframework.aot.hint.RuntimeHints hints, ClassLoader classLoader) {
73+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
7974
registerReflectionHints(hints);
8075

8176
registerResourcesHints(hints);
8277

8378
registerSerializationHints(hints);
8479
}
8580

86-
private static void registerSerializationHints(org.springframework.aot.hint.RuntimeHints hints) {
81+
private static void registerSerializationHints(RuntimeHints hints) {
8782
hints.serialization()
8883
.registerType(HashMap.class)
8984
.registerType(ArrayList.class)
@@ -107,23 +102,6 @@ private static void registerResourcesHints(org.springframework.aot.hint.RuntimeH
107102

108103
@SneakyThrows
109104
private static void registerReflectionHints(org.springframework.aot.hint.RuntimeHints hints) {
110-
Set.of(new java.lang.reflect.Method[] { findMethod(UiController.Settings.class, "getTitle"),
111-
findMethod(UiController.Settings.class, "getBrand"),
112-
findMethod(UiController.Settings.class, "getLoginIcon"),
113-
findMethod(UiController.Settings.class, "getFavicon"),
114-
findMethod(UiController.Settings.class, "getFaviconDanger"),
115-
findMethod(UiController.Settings.class, "getPollTimer"),
116-
findMethod(UiController.Settings.class, "getTheme"),
117-
findMethod(UiController.Settings.class, "isNotificationFilterEnabled"),
118-
findMethod(UiController.Settings.class, "isRememberMeEnabled"),
119-
findMethod(UiController.Settings.class, "getAvailableLanguages"),
120-
findMethod(UiController.Settings.class, "getRoutes"),
121-
findMethod(UiController.Settings.class, "getExternalViews"),
122-
findMethod(UiController.Settings.class, "getViewSettings"), findMethod(UiController.class, "index"),
123-
findMethod(AdminServerUiProperties.UiTheme.class, "getPalette"),
124-
findMethod(AdminServerUiProperties.UiTheme.class, "getColor") })
125-
.forEach((method) -> hints.reflection().registerMethod(method, ExecutableMode.INVOKE));
126-
127105
Class<?> queryEndpointStrategyResponse = Class
128106
.forName("de.codecentric.boot.admin.server.services.endpoints.QueryIndexEndpointStrategy$Response");
129107
Class<?> queryEndpointStrategyResponseEndpointRef = Class.forName(
@@ -134,7 +112,13 @@ private static void registerReflectionHints(org.springframework.aot.hint.Runtime
134112
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
135113
.registerType(queryEndpointStrategyResponseEndpointRef, MemberCategory.INVOKE_PUBLIC_METHODS,
136114
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
137-
.registerType(Application.Builder.class, MemberCategory.INVOKE_PUBLIC_METHODS,
115+
.registerType(UiController.Settings.class, MemberCategory.INVOKE_PUBLIC_METHODS,
116+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
117+
.registerType(AdminServerUiProperties.UiTheme.class, MemberCategory.INVOKE_PUBLIC_METHODS,
118+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
119+
.registerType(AdminServerUiProperties.Palette.class, MemberCategory.INVOKE_PUBLIC_METHODS,
120+
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
121+
.registerType(CssColorUtils.class, MemberCategory.INVOKE_PUBLIC_METHODS,
138122
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
139123
.registerType(InstanceDeregisteredEvent.class, MemberCategory.INVOKE_PUBLIC_METHODS,
140124
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
@@ -152,8 +136,6 @@ private static void registerReflectionHints(org.springframework.aot.hint.Runtime
152136
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
153137
.registerType(InstanceId.class, MemberCategory.INVOKE_PUBLIC_METHODS,
154138
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
155-
.registerType(Application.class, MemberCategory.INVOKE_PUBLIC_METHODS,
156-
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
157139
.registerType(Endpoint.class, MemberCategory.INVOKE_PUBLIC_METHODS,
158140
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
159141
.registerType(Instance.class, MemberCategory.INVOKE_PUBLIC_METHODS,
@@ -164,10 +146,6 @@ private static void registerReflectionHints(org.springframework.aot.hint.Runtime
164146
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
165147
.registerType(InstanceWebProxy.ForwardRequest.class, MemberCategory.INVOKE_PUBLIC_METHODS,
166148
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
167-
.registerType(AdminServerUiProperties.Palette.class, MemberCategory.INVOKE_PUBLIC_METHODS,
168-
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
169-
.registerType(CssColorUtils.class, MemberCategory.INVOKE_PUBLIC_METHODS,
170-
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
171149

172150
.registerType(BuildVersionMixin.class, MemberCategory.INVOKE_PUBLIC_METHODS,
173151
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
@@ -202,9 +180,7 @@ private static void registerReflectionHints(org.springframework.aot.hint.Runtime
202180
.registerConstructor(
203181
queryEndpointStrategyResponseEndpointRef.getDeclaredConstructor(String.class, boolean.class),
204182
ExecutableMode.INVOKE)
205-
.registerConstructor(Application.Builder.class.getDeclaredConstructor(), ExecutableMode.INVOKE)
206-
.registerMethod(Application.Builder.class.getMethod("build"), ExecutableMode.INVOKE)
207-
.registerMethod(Application.class.getMethod("builder"), ExecutableMode.INVOKE)
183+
208184
.registerConstructor(Registration.class.getDeclaredConstructor(String.class, String.class, String.class,
209185
String.class, String.class, Map.class), ExecutableMode.INVOKE)
210186
.registerConstructor(Registration.Builder.class.getDeclaredConstructor(), ExecutableMode.INVOKE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014-2020 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 de.codecentric.boot.admin.server.ui.config;
18+
19+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
20+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21+
import org.springframework.context.annotation.Conditional;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.ImportRuntimeHints;
24+
25+
import de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration;
26+
import de.codecentric.boot.admin.server.config.AdminServerWebConfiguration;
27+
import de.codecentric.boot.admin.server.config.SpringBootAdminServerEnabledCondition;
28+
29+
@Configuration(proxyBeanMethods = false)
30+
@Conditional(SpringBootAdminServerEnabledCondition.class)
31+
@ConditionalOnBean(AdminServerMarkerConfiguration.Marker.class)
32+
@AutoConfigureAfter(AdminServerWebConfiguration.class)
33+
@ImportRuntimeHints({ ServerRuntimeHints.class })
34+
public class SpringNativeServerAutoConfiguration {
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration
2+
de.codecentric.boot.admin.server.ui.config.SpringNativeServerAutoConfiguration

0 commit comments

Comments
 (0)