Skip to content

Commit a0cb697

Browse files
committed
Add runtime hints. Removed unused dependency.
1 parent e4a9ecb commit a0cb697

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

spring-cloud-zookeeper-core/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
<artifactId>spring-boot-starter-actuator</artifactId>
5454
<optional>true</optional>
5555
</dependency>
56-
<dependency>
57-
<groupId>org.springframework.boot</groupId>
58-
<artifactId>spring-boot-starter-validation</artifactId>
59-
</dependency>
6056
<dependency>
6157
<groupId>org.springframework.cloud</groupId>
6258
<artifactId>spring-cloud-commons</artifactId>

spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@
2222
import org.apache.curator.drivers.TracerDriver;
2323
import org.apache.curator.ensemble.EnsembleProvider;
2424
import org.apache.curator.framework.CuratorFramework;
25+
import org.apache.curator.x.discovery.UriSpec;
26+
import org.apache.zookeeper.ClientCnxnSocketNIO;
2527

28+
import org.springframework.aot.hint.MemberCategory;
29+
import org.springframework.aot.hint.RuntimeHints;
30+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
31+
import org.springframework.aot.hint.TypeReference;
2632
import org.springframework.beans.factory.ObjectProvider;
2733
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2834
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2935
import org.springframework.context.annotation.Bean;
3036
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.util.ClassUtils;
3138

3239
/**
3340
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -67,3 +74,31 @@ public RetryPolicy exponentialBackoffRetry(ZookeeperProperties properties) {
6774
}
6875

6976
}
77+
78+
// TODO: remove after GraalVM metadata PR merged
79+
class ZookeeperCoreHints implements RuntimeHintsRegistrar {
80+
81+
@Override
82+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
83+
if (!ClassUtils.isPresent("org.apache.zookeeper.ZooKeeper", classLoader)) {
84+
return;
85+
}
86+
hints.reflection().registerType(TypeReference.of(ClientCnxnSocketNIO.class),
87+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
88+
hints.reflection()
89+
.registerType(TypeReference.of("org.apache.curator.x.discovery.details.OldServiceInstance"),
90+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
91+
MemberCategory.INVOKE_DECLARED_METHODS));
92+
hints.reflection()
93+
.registerType(TypeReference.of("org.apache.curator.x.discovery.UriSpec"),
94+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
95+
MemberCategory.INVOKE_DECLARED_METHODS));
96+
hints.reflection().registerType(TypeReference.of(UriSpec.Part.class),
97+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
98+
MemberCategory.INVOKE_DECLARED_METHODS));
99+
hints.reflection()
100+
.registerType(TypeReference.of("org.apache.curator.x.discovery.ServiceInstance"),
101+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
102+
MemberCategory.INVOKE_DECLARED_METHODS));
103+
}
104+
}
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+
org.springframework.cloud.zookeeper.ZookeeperCoreHints

spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import org.apache.curator.framework.CuratorFramework;
2020
import org.apache.curator.x.discovery.ServiceDiscovery;
2121

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;
2226
import org.springframework.beans.factory.annotation.Autowired;
2327
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
2428
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -32,6 +36,7 @@
3236
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
3337
import org.springframework.context.annotation.Bean;
3438
import org.springframework.context.annotation.Configuration;
39+
import org.springframework.util.ClassUtils;
3540

3641
/**
3742
* @author Spencer Gibb
@@ -81,3 +86,21 @@ public ZookeeperDiscoveryHealthIndicator zookeeperDiscoveryHealthIndicator(
8186
}
8287

8388
}
89+
90+
class ZookeeperDiscoveryHints implements RuntimeHintsRegistrar {
91+
92+
@Override
93+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
94+
if (!ClassUtils.isPresent("org.apache.zookeeper.ZooKeeper", classLoader)) {
95+
return;
96+
}
97+
hints.reflection()
98+
.registerType(TypeReference.of(ZookeeperInstance.class),
99+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
100+
MemberCategory.INVOKE_DECLARED_METHODS));
101+
hints.reflection().registerType(TypeReference.of(ZookeeperServiceInstance.class),
102+
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
103+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
104+
}
105+
}
106+
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+
org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryHints

src/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
44
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
55
<suppressions>
6-
<suppress files=".*ZookeeperPropertySourceLocatorTests\.java" checks="JavadocVariable"/>
6+
<suppress files=".*Tests\.java" checks="JavadocVariable"/>
77
</suppressions>

0 commit comments

Comments
 (0)