spring-aot compiling process jedis-HostandPort class which cause exception when packaging

43 Views Asked by At
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

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.6</version>
        <relativePath/>
    </parent>

 <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                            <mainClass>${mainClass}</mainClass>
                        </configuration>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>

                    <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>

dear Wilkinson suggest for create new class as a configuration class and create HostandPort class when should use.

but in my project ,jediscluster config has been code like below,

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

and it will still report same exception when i package-native.

i have try to find a new class insteading HostandPort class, but it does not work, still reports exception.

i wanna try to coding some custom hint for aot-compling, but there is no more example or suggest for me to continue and import.

0

There are 0 best solutions below