Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring aot compile doesnot process jedis-HostandPort class which cause below exception when packaging can somebody tell me how to fix #198

Closed
sintoku921 opened this issue Jan 2, 2024 · 4 comments

Comments

@sintoku921
Copy link

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

org.springframework.boot spring-boot-maven-plugin ${mainClass} repackage org.projectlombok lombok
                <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>
@sintoku921 sintoku921 changed the title spring aot compile doesnot process jedis-HostandPort class which case below exception when pacaging can somebody tell me how to fix spring aot compile doesnot process jedis-HostandPort class which cause below exception when packaging can somebody tell me how to fix Jan 2, 2024
@wilkinsona
Copy link
Member

wilkinsona commented Jan 2, 2024

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.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2024
@sintoku921
Copy link
Author

sintoku921 commented Jan 2, 2024

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.

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

@sintoku921
Copy link
Author

sintoku921 commented Jan 2, 2024

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())));
    }
}

@scottfrederick
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants