Skip to content

Naive & AOT

huiche支持使用GraalVM在native模式运行,但因为使用了反射,你需要自行配置好AOT

huiche内部会被反射操作的类

  • 实体类
  • 查询结果类(VO/DTO等),比如各种listAs,pageAs,getAs等指定的查询结果类型的类
  • 筛选对象类(Search), 使用@Search注解的筛选对象类
  • 插入(insertWith)/更新(updateWith)的值承载类(Req/VO等)

spring的AOT配置

java
// 实现RuntimeHintsRegistrar
public class HuicheRuntimeHints implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
        // 所有实体类,请求类,Search类的包名
        for (String pkg : List.of("xxx.entity", "xxx.request", "xxx.search")) {
            ClassScanner.scan(pkg, clazz -> true).forEach(clazz ->
                    hints.reflection().registerType(clazz, MemberCategory.values())
            );
        }
    }
}
// 导入到配置类或启动类
@SpringBootApplication
@ImportRuntimeHints(HuicheRuntimeHints.class)
public class App {
    static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

示例使用了org.huiche.core.support.ClassScanner 来按包名扫描类, 你可以自行换用其他喜好的方式,或者直接手动注册,或者是使用GraalVM的“跟踪代理”自动生成配置

如果使用了lambda表达式, 你可能还需要配置lambda表达式