ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Spring boot 启动性能优化

2022-08-10 15:31:21  阅读:143  来源: 互联网

标签:Spring boot component spring Indexed 注解 优化


spring boot启动性能优化

spring boot中使用spring-context-indexer加快启动速度

Spring中@ComponentScan扫描的package包含的类越多的时候,Spring模式注解解析耗时就越长,服务启动时候就越长,针对此问题Spring提供了@Indexed注解来添加索引。
查看@Serive、@Controller、@Repository、@Component注解源码会发现已经自动添加了此@Indexed注解

 1 @Target(ElementType.TYPE)
 2 @Retention(RetentionPolicy.RUNTIME)
 3 @Documented
 4 @Indexed
 5 public @interface Component {
 6 
 7     /**
 8      * The value may indicate a suggestion for a logical component name,
 9      * to be turned into a Spring bean in case of an autodetected component.
10      * @return the suggested component name, if any (or empty String otherwise)
11      */
12     String value() default "";
13 
14 }

所以只需要在项目的添加spring-context-indexer的依赖即可
maven中:

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-indexer</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

这样启动效率就提升了。
会发现在编译后生成了META-INF/spring.components文件
@Indexed,可以预编译,跟lombok一样在编译期处理。

标签:Spring,boot,component,spring,Indexed,注解,优化
来源: https://www.cnblogs.com/SEU-ZCY/p/16572603.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有