Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #10375] Support springboot3 and native-image #306

Merged

Conversation

SuperZ1999
Copy link
Contributor

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

What is the purpose of the change

适配springboot3 和 native-image

Brief changelog

适配SpringBoot3

根据SpringBoot3的自动配置方式,添加org.springframework.boot.autoconfigure.AutoConfiguration.imports文件,然后更新依赖的nacos-spring-context版本

支持native-image

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

Verifying this change

适配SpringBoot3

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

支持native-image

新建一个项目,导入所有starter和actuator项目,开启GraalVM的Tracing Agent功能(运行java程序时添加参数:-agentlib:native-image-agent=config-output-dir=/path/to/config-dir/),将https://nacos.io/zh-cn/docs/nacos-spring.html里的功能测试一遍,之后将生成的配置文件拷贝到META-INF/native-image下,再使用spring-boot-maven-plugin的process-aot和native-maven-plugin的compile功能,运行mvn clean package -Pnative即可生成可执行程序。
运行生成的可执行程序,再将https://nacos.io/zh-cn/docs/nacos-spring.html里的功能测试一遍,功能正常即测试通过

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

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@hujun-w-2 hujun-w-2 merged commit 3108158 into nacos-group:summer-ospp#10375 Oct 6, 2023
hujun-w-2 added a commit that referenced this pull request Dec 3, 2023
* [ISSUE #10375] Support springboot3 and native-image (#306)

* [ISSUE #10375] Support SpringBoot3

* [ISSUE #10375] Support native-image

* [ISSUE #10375] Update document and add AOT sample (#307)

Update document and add AOT sample

---------

Co-authored-by: SuperZ1999 <34301918+SuperZ1999@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants