You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GraalVM的@TypeHint未被Spring-AOT识别 未写入reflect-config.json

@TypeHint注解未生成reflect-config.json的解决方案

核心错误原因

@TypeHint注解不能直接标注在@SpringBootApplication启动类上,AOT处理程序默认不会扫描启动类上的该注解,必须绑定到RuntimeHintsRegistrar实现类后手动导入到上下文才能生效。

修复操作步骤

1. 自定义RuntimeHints注册类

新建类实现RuntimeHintsRegistrar接口,将@TypeHint注解标注在该类上:

import org.springframework.aot.hint.AccessBits;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.annotation.TypeHint;

@TypeHint(
        typeNames = "org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi",
        access = AccessBits.PUBLIC_CONSTRUCTORS | AccessBits.PUBLIC_METHODS
)
public class BouncyCastleHintsRegistrar implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
        // 若需要更灵活的配置,也可在此处通过代码手动注册反射规则,与@TypeHint效果等价
    }
}

2. 导入注册类到Spring上下文

在启动类上添加@ImportRuntimeHints注解,引入刚才创建的注册类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints;

@SpringBootApplication
@ImportRuntimeHints(BouncyCastleHintsRegistrar.class)
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

其他排查方向

  • 确认@TypeHint的包路径为org.springframework.aot.hint.annotation.TypeHint,避免引入其他同名注解。
  • 检查Spring Boot版本与spring-aot插件版本大版本完全一致,版本不兼容会导致注解扫描逻辑失效。
  • 执行mvn clean spring-aot:generate前先清空target目录,避免旧缓存影响生成结果。
  • 多模块项目中需确保注册类所在模块已被主启动模块依赖,AOT插件执行时可扫描到该类。

内容的提问来源于stack exchange,提问作者Liki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 20:27:04