spring aot compile doesnot process jedis-HostandPort class which cause below exception when packaging can somebody tell me how to fix
sintoku921 opened this issue · 4 comments
102 18:24:05.549 1 HallMainStarter51: Starting HallMainStarter using Java 17.0.9 with PID 4639 (/Users/andy/hall/wepoker-hall/target/classes started by andy in /Users/andy/hall/wepoker-hall)
0102 18:24:05.550 1 HallMainStarter644: The following 1 profile is active: "dev"
Exception in thread "main" org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it:
redis.clients.jedis.HostAndPort
at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:100)
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:110)
at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:80)
maven config like below
org.springframework.boot
spring-boot-starter-parent
3.1.6
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.28</version>
<configuration>
<buildArgs>
--initialize-at-build-time=org.springframework.util.unit.DataSize
--initialize-at-build-time=org.slf4j.MDC
--initialize-at-build-time=ch.qos.logback.classic.Level
--initialize-at-build-time=ch.qos.logback.classic.Logger
--initialize-at-build-time=ch.qos.logback.core.util.StatusPrinter
--initialize-at-build-time=ch.qos.logback.core.status.StatusBase
--initialize-at-build-time=ch.qos.logback.core.status.InfoStatus
--initialize-at-build-time=ch.qos.logback.core.spi.AppenderAttachablelmpl
--initialize-at-build-time=org.slf4j.LoggerFactory
--initialize-at-build-time=ch.qos.logback.core.util.Loader
--initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder
--initialize-at-build-time=ch.qos.logback.classic.spi.ThrowableProxy
--initialize-at-build-time=ch.qos.logback.core.CoreConstants
--initialize-at-build-time=redis.clients.jedis.HostAndPort
--report-unsupported-elements-at-runtime
--allow-incomplete-classpath
-H:+ReportExceptionStackTraces
</buildArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
You appear to be trying to bind configuration properties directly to redis.clients.jedis.HostAndPort
. That won't work in a native image as the class has not been compiled with -parameters
. Rather than binding directly to HostAndPort
you should bind properties to a class that you control and can compile with -parameters
. An instance of HostAndPort
can then be created from the instance of your own class.
If you have any further questions, please follow up on Stack Overflow or Gitter. We prefer to use GitHub issues only for bugs and enhancements.
You appear to be trying to bind configuration properties directly to
redis.clients.jedis.HostAndPort
. That won't work in a native image as the class has not been compiled with-parameters
. Rather than binding directly toHostAndPort
you should bind properties to a class that you control and can compile with-parameters
. An instance ofHostAndPort
can then be created from the instance of your own class.If you have any further questions, please follow up on Stack Overflow or Gitter. We prefer to use GitHub issues only for bugs and enhancements.
do you mean i create a sub class as extends HostandPort class ,and try to compile ? thks and i will try and get a response
i have used a dataClass init configuration for jedis config insteadof use HostAndPort class directly,like below ,but the exeception still ouucred while native compiling .
@ConfigurationProperties(prefix = "jedis")
@Data
public class RedisConfigProperties {
// host list
private List<RedisHost> hosts = new ArrayList<>();
@Data
public static class RedisHost{
private String host;
private int port;
}
public Set<HostAndPort> getRedisHosts(){
return new HashSet<>(U.map(hosts, o -> new HostAndPort(o.getHost(), o.getPort())));
}
}
As Andy stated above:
If you have any further questions, please follow up on Stack Overflow or Gitter. We prefer to use GitHub issues only for bugs and enhancements.
Please post your question as suggested, with as much detail and sample code as possible so that the community can try to help you.