Skip to content

Commit a08ebc1

Browse files
Add GraalVM Native Image support (#856)
Fixes #468, #673, #1021, #1040 --------- Co-authored-by: Maciej Walkowiak <[email protected]>
1 parent 98a7863 commit a08ebc1

File tree

19 files changed

+430
-3
lines changed

19 files changed

+430
-3
lines changed

docs/src/main/asciidoc/core.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,12 @@ There can be multiple customizer beans present in single application context and
260260

261261
Client-specific customizations can be applied through client-specific customizer interfaces (for example `S3ClientCustomizer` for S3). See integrations documentation for details.
262262

263+
264+
=== GraalVM Native Image
265+
266+
Since version 3.3.0 the framework provides **experimental** support for GraalVM Native Image build.
267+
268+
Known issues are:
269+
270+
- in DynamoDB integration, `StaticTableSchema` must be used instead of `DynamicTableSchema` (see https://github.com/aws/aws-sdk-java-v2/issues/2445)
271+
- in S3 integration, when working with CRT client, following guide must be followed: https://github.com/awslabs/aws-crt-java?tab=readme-ov-file#graalvm-support
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2013-2023 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+
package io.awspring.cloud.autoconfigure.config;
17+
18+
import io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStorePropertySources;
19+
import io.awspring.cloud.autoconfigure.config.secretsmanager.SecretsManagerPropertySources;
20+
import io.awspring.cloud.parameterstore.ParameterStorePropertySource;
21+
import io.awspring.cloud.secretsmanager.SecretsManagerPropertySource;
22+
import org.springframework.aot.hint.MemberCategory;
23+
import org.springframework.aot.hint.RuntimeHints;
24+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
25+
import org.springframework.aot.hint.TypeReference;
26+
import org.springframework.util.ClassUtils;
27+
28+
public class ConfigStoreRuntimeHints implements RuntimeHintsRegistrar {
29+
30+
@Override
31+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
32+
if (ClassUtils.isPresent("io.awspring.cloud.parameterstore.ParameterStorePropertySource", classLoader)) {
33+
hints.reflection().registerType(TypeReference.of(ParameterStorePropertySources.class),
34+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
35+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
36+
hints.reflection().registerType(TypeReference.of(ParameterStorePropertySource.class),
37+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
38+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
39+
}
40+
41+
if (ClassUtils.isPresent("io.awspring.cloud.secretsmanager.SecretsManagerPropertySource", classLoader)) {
42+
hints.reflection().registerType(TypeReference.of(SecretsManagerPropertySources.class),
43+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
44+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
45+
46+
hints.reflection().registerType(TypeReference.of(SecretsManagerPropertySource.class),
47+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
48+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
49+
}
50+
51+
}
52+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2013-2023 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+
package io.awspring.cloud.autoconfigure.core;
17+
18+
import org.springframework.aot.hint.MemberCategory;
19+
import org.springframework.aot.hint.RuntimeHints;
20+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
21+
import org.springframework.aot.hint.TypeReference;
22+
import org.springframework.util.ClassUtils;
23+
24+
public class CoreAOT implements RuntimeHintsRegistrar {
25+
26+
private static final String STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER = "software.amazon.awssdk.services.sts.auth.StsWebIdentityTokenFileCredentialsProvider";
27+
28+
@Override
29+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
30+
if (ClassUtils.isPresent(STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER, classLoader)) {
31+
hints.reflection().registerType(TypeReference.of(STS_WEB_IDENTITY_TOKEN_FILE_CREDENTIALS_PROVIDER),
32+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
33+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
34+
}
35+
}
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
io.awspring.cloud.autoconfigure.config.ConfigStoreRuntimeHints,\
3+
io.awspring.cloud.autoconfigure.core.CoreAOT
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2013-2023 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+
package io.awspring.cloud.core;
17+
18+
import org.springframework.aot.hint.RuntimeHints;
19+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
20+
21+
public class AWSCoreRuntimeHints implements RuntimeHintsRegistrar {
22+
23+
@Override
24+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
25+
hints.resources().registerPattern("io/awspring/cloud/core/SpringCloudClientConfiguration.properties");
26+
}
27+
}

spring-cloud-aws-core/src/main/java/io/awspring/cloud/core/SpringCloudClientConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,4 @@ public ClientOverrideConfiguration clientOverrideConfiguration() {
6666
private String getUserAgent() {
6767
return NAME + "/" + version;
6868
}
69-
7069
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
io.awspring.cloud.core.AWSCoreRuntimeHints
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
io.awspring.cloud.s3.S3RuntimeHints
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2013-2023 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+
package io.awspring.cloud.s3;
17+
18+
import org.springframework.aot.hint.RuntimeHints;
19+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
20+
21+
public class S3RuntimeHints implements RuntimeHintsRegistrar {
22+
@Override
23+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
24+
hints.resources().registerPattern("io/awspring/cloud/s3/S3ObjectContentTypeResolver.properties");
25+
}
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2013-2023 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+
package io.awspring.cloud.sns;
17+
18+
import io.awspring.cloud.sns.handlers.NotificationMessageHandlerMethodArgumentResolver;
19+
import io.awspring.cloud.sns.handlers.NotificationStatus;
20+
import io.awspring.cloud.sns.handlers.NotificationStatusHandlerMethodArgumentResolver;
21+
import io.awspring.cloud.sns.handlers.NotificationSubjectHandlerMethodArgumentResolver;
22+
import java.util.stream.Stream;
23+
import org.springframework.aot.hint.MemberCategory;
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
26+
import org.springframework.aot.hint.TypeReference;
27+
28+
public class SnsRuntimeHints implements RuntimeHintsRegistrar {
29+
@Override
30+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
31+
Stream.of(NotificationStatusHandlerMethodArgumentResolver.class,
32+
NotificationStatusHandlerMethodArgumentResolver.AmazonSnsNotificationStatus.class,
33+
NotificationMessageHandlerMethodArgumentResolver.class,
34+
NotificationMessageHandlerMethodArgumentResolver.ByteArrayHttpInputMessage.class,
35+
NotificationSubjectHandlerMethodArgumentResolver.class, NotificationStatus.class)
36+
.forEach(type -> hints.reflection().registerType(TypeReference.of(type),
37+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
38+
MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS)));
39+
}
40+
}

0 commit comments

Comments
 (0)