nacos-group / nacos-spring-project

Nacos ECO Project for Spring Framework
https://nacos.io/
Apache License 2.0
754 stars 309 forks source link

[ISSUE #321] Support spring 6.x and native-image #322

Closed SuperZ1999 closed 11 months ago

SuperZ1999 commented 11 months ago

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

适配Spring6.x 和 native-image

Brief changelog

适配Spring6

spring-context-support 里面的AbstractAnnotationBeanPostProcessor类继承的InstantiationAwareBeanPostProcessorAdapter类在spring 6.x已经被删除,在nacos-spring-context项目里新建AbstractAnnotationBeanPostProcessor类并改为实现InstantiationAwareBeanPostProcessor,涉及此类的都替换掉新建的AbstractAnnotationBeanPostProcessor

支持native-image

  1. 首先新建nacos-spring-context-aot项目,该项目的作用是springboot插件的process-aot目标运行时扫描所有添加的bean,如果bean里使用了@NacosInjected注解或@NacosValue注解,就把注解标注的属性添加到reflect-config.json里面
  2. 因为AOT运行时Spring不会调用ImportBeanDefinitionRegistrar的registerBeanDefinitions方法,所以将registerBeanDefinitions方法中除了注册BeanDefinition操作的其他操作放到EnableNacosAotProcessor里,EnableNacosDiscoveryAotProcessor和EnableNacosConfigAotProcessor同理
  3. AOT运行时@NacosPropertySource注解标注的类的BeanDefinition是RootBeanDefinition,需要将这些RootBeanDefinition转换为AnnotatedGenericBeanDefinition

Verifying this change

适配Spring6

首先将https://nacos.io/zh-cn/docs/nacos-spring.html里的功能都debug测试一遍,debug时统计没有走到的代码,然后运行以下单元测试即可测试上述没有走到的代码:

Follow this checklist to help us incorporate your contribution quickly and easily:

hujun-w-2 commented 11 months ago

Please also post the design document link in PR.