Spring Framework 7.033.AOT 处理

Spring Framework 7.033.AOT 处理

Spring Framework 从 6.0 版本开始引入了对AOT(Ahead-of-Time,提前编译) 的支持,这是一种在应用部署前(而非运行时)执行某些处理步骤的技术。AOT 处理能够优化 Spring 应用的启动性能、减少内存占用,并支持将应用编译为原生镜像(如使用 GraalVM Native Image)。

AOT 的核心目标

AOT 处理旨在解决传统 Spring 应用的一些局限性,尤其是在启动阶段:

  • 减少启动时间:将运行时的Bean定义解析、依赖注入等工作提前到构建时完成。
  • 降低内存占用:通过移除运行时不需要的组件(如类解析器、XML处理器),减小应用体积。
  • 支持原生镜像:为 GraalVM Native Image 等技术提供必要的元数据,确保反射、资源访问等操作在原生环境中正常工作。
  • 优化执行效率:允许编译器在提前编译时进行更深度的优化。

AOT 处理的核心概念

1. 提前处理(Ahead-of-Time Processing)

在构建阶段,Spring 会执行一系列 AOT

Retrieving import origins if necessary org.springframework.aot.context.bootstrap.generator.BeanDefinitionGenerationException: Failed to handle bean with name 'mapInfoServiceImpl' and type 'com.jingansi.dushu.biz.service.map.impl.MapInfoServiceImpl' at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.writeBeanDefinitions(ApplicationContextAotProcessor.java:138) at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.bootstrapMethod(ApplicationContextAotProcessor.java:104) at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.process(ApplicationContextAotProcessor.java:96) at org.springframework.aot.build.ContextBootstrapContributor.contribute(ContextBootstrapContributor.java:80) at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:91) at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:71) at org.springframework.aot.build.GenerateBootstrapCommand.call(GenerateBootstrapCommand.java:107) at org.springframework.aot.build.GenerateBootstrapCommand.call(GenerateBootstrapCommand.java:42) at picocli.CommandLine.executeUserObject(CommandLine.java:1953) at picocli.CommandLine.access$1300(CommandLine.java:145) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352) at picocli.CommandLine$RunLast.handle(CommandLine.java:2346) at picocli.CommandLine$RunLast.handle(CommandLine.java:2311) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179) at picocli.CommandLine.execute(CommandLine.java:2078) at org.springframework.aot.build.GenerateBootstrapCommand.main(GenerateBootstrapCommand.java:112) Caused by: java.lang.IllegalStateException: Multiple privileged packages: [com.baomidou.mybatisplus.extension.service.impl, com.jingansi.dushu.biz.service.map.impl] at org.springframework.aot.context.bootstrap.generator.infrastructure.ProtectedAccessAnalysis
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员勇哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值