• Spring 6.x 的 AoT 相关支持的注解


    RegisterReflectionForBinding

    RegisterReflectionForBinding在构建期间.使用RegisterReflectionForBindingProcessor 来注册相关类的元数据. 详情看org.springframework.aot.hint.BindingReflectionHintsRegistrar 类的处理.
    不仅会处理当前类. 还会处理其方法和方法参数和返回值的相关类. 仅仅处理与反射相关的操作. 一些动态代理. 序列化. 资源文件.等处理不了.

    ImportRuntimeHints

    ImportRuntimeHints 可控.更加灵活的处理相关类的元数据. 不仅可以处理反射. 资源. 序列化也可以处理. 指定相关RuntimeHintsRegistrar的子类. for-example:

    @SpringBootApplication
    @ImportRuntimeHints(AccountService.AccountRuntimeHints.class)
    public class AccountService {
    
        public static void main(String[] args) {
    
            SpringApplication.run(AccountService.class, args);
        }
       static class AccountRuntimeHints implements RuntimeHintsRegistrar {
    
            @Override
            public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
                ReflectionHints ref = hints.reflection();
                try {
                    for (Class<?> c : getK8sClasses()) {
                        ref.registerType(c, MemberCategory.values());
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
    
            private Collection<? extends Class<?>> getK8sClasses() {
                Set<Class<?>> classes = new HashSet<>();
                return classes;
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    Reflective

    标注哪些类是需要被反射的. 会自动处理

    使用BeanFactoryInitializationAotProcessor

    • 可以在build阶段动态注册某些bean, 例如对Feign的支持. 就是使用这种方式在构建阶段生成Feign的实现类动态注册到spring context中. 参考 注册Feign 实例相关源码:org.springframework.cloud.openfeign.aot.FeignClientBeanFactoryInitializationAotProcessor
    使用aot.factories 注册BeanFactoryInitializationAotProcessor

    org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=

    如何debug Spring的AoT的编译阶段.

       public static void main(String[] args) throws Exception {
            args = new String[]{"spring.cloud.kubernetes.example.account.AccountService",
                    "/Users/apple/opensource/spring-cloud-kubernetes-microservices-toolkit/example-service-account/build/generated/aotSources",
                    "/Users/apple/opensource/spring-cloud-kubernetes-microservices-toolkit/example-service-account/build/generated/aotResources",
                    "/Users/apple/opensource/spring-cloud-kubernetes-microservices-toolkit/example-service-account/build/generated/aotClasses",
                    "spring.cloud.kubernetes.example.account",
                    "example-service-account"};
            SpringApplicationAotProcessor.main(args);
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • spring.cloud.kubernetes.example.account.AccountService 主类
    • spring.cloud.kubernetes.example.account 主包
    • example-service-account 模块名
    • 其他的三个为代码生成的路径

    一个spring-cloud-kubernetes的本地debug的开发工具包.并支持native

  • 相关阅读:
    企业有了BI,为什么还需要以指标为核心的ABI平台?
    【寒武纪(9)】MLU架构
    分布式计算框架——MapReduce
    Locust 断言的实现?
    2-5基础配置-Win2003增加攻击面
    sentinel
    Vue源码makeMap解析【详细】
    js逆向播放量增加,增加视频热度,uuid,sid,buvid3,aid,b_lsid, b_nut 还原实现过程
    JS——垃圾回收的原理
    计蒜客详解合集(1)期
  • 原文地址:https://blog.csdn.net/u014087707/article/details/128201789