Hazelcast 与 Spring Boot 3 GraalVM Native NoSuchMethodError

问题描述 投票:0回答:1

将 Spring Cloud Gateway 项目迁移到 Spring Boot 3.1.2 和以下本机配置

{
  "resources":{
    "includes":[
      {"pattern":"hazelcast.yaml"}
    ]}
}

已配置的 Hazelcast beans,它们可以通过 GraalVM 运行时搜索找到

public class CacheConfig__BeanDefinitions {

  public static BeanDefinition getCacheConfigBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(CacheConfig.class);
    beanDefinition.setInstanceSupplier(CacheConfig::new);
    return beanDefinition;
  }

  private static BeanInstanceSupplier<HazelcastInstance> getHazelcastInstanceInstanceSupplier() {
    return BeanInstanceSupplier.<HazelcastInstance>forFactoryMethod(CacheConfig.class, "hazelcastInstance", Config.class)
            .withGenerator((registeredBean, args) -> registeredBean.getBeanFactory().getBean(CacheConfig.class).hazelcastInstance(args.get(0)));
  }

  public static BeanDefinition getHazelcastInstanceBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setTargetType(HazelcastInstance.class);
    beanDefinition.setDestroyMethodNames("shutdown");
    beanDefinition.setInstanceSupplier(getHazelcastInstanceInstanceSupplier());
    return beanDefinition;
  }

  private static BeanInstanceSupplier<Config> getHazelCastConfigInstanceSupplier() {
    return BeanInstanceSupplier.<Config>forFactoryMethod(CacheConfig.class, "hazelCastConfig", String.class, CacheConfigurationProperties.class)
            .withGenerator((registeredBean, args) -> registeredBean.getBeanFactory().getBean(CacheConfig.class).hazelCastConfig(args.get(0), args.get(1)));
  }

  public static BeanDefinition getHazelCastConfigBeanDefinition() {
    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setTargetType(Config.class);
    beanDefinition.setInstanceSupplier(getHazelCastConfigInstanceSupplier());
    return beanDefinition;
  }

配置类 Hazelcast beans 在 has 中进行配置

@Configuration(proxyBeanMethods = false)

hazelcast.yaml

hazelcast:
  network:
    join:
      multicast:
        enabled: false

但是,运行应用程序时出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsRegistrarConfiguration': Instantiation of supplied bean failed
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1220) ~[api-gateway:6.0.11]
Caused by: java.lang.ExceptionInInitializerError: null
        at io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics.<init>(HazelcastCacheMetrics.java:79) ~[api-gateway:1.11.2]
Caused by: java.lang.NoSuchMethodException: no such method: com.hazelcast.map.IMap.getName()String/invokeInterface
Caused by: java.lang.NoSuchMethodError: com.hazelcast.map.IMap.getName()

我无法弄清楚在调试 GraalVM 应用程序时遇到

String/invokeInterface
时应该做什么。

尝试通过以下方式解决:

  1. 包含可达性元数据,其中包括 Hazelcast 5.2.1 运行时提示
  2. https://docs.hazelcast.org/docs/5.1/javadoc/com/hazelcast/map/IMap.html
  3. 已添加
{
        "condition": {
          "typeReachable": "io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics"
        },
        "name": " com.hazelcast.map.IMap",
        "methods": [
          {
            "name": "getName",
            "parameterTypes": []
          }
        ]
      }

根据我对错误的理解,问题源于 Spring Boot Actuator 尝试访问 Hazelcast 缓存统计数据/指标,但无法找到 IMap 方法。

我不确定如何提示运行时在构建时意识到这一点。

spring-boot hazelcast graalvm-native-image spring-native
1个回答
0
投票

也遇到了这个问题,可悲的是。 据我所知,这是 Micrometer 方面的一个错误,因此在那里报告: https://github.com/micrometer-metrics/micrometer/issues/5604

© www.soinside.com 2019 - 2024. All rights reserved.