springboot项目启动慢的问题排查方式
目录
- springboot项目启动慢的问题排查
- 1.最开始查看的启动日志,是在输出:
- 2. 启动项目,打印日志级别改为debug,查看更详细信息
- 如何优化SpringBoot的项目的启动速度
- 实际上它是下面三个注解的组合
- 可以用@SpringBootApplication注解下面的属性
springboot项目启动慢的问题排查 springboot项目,随着时间的推移,启动耗时逐步增加,从几分钟慢慢的达到30多分钟,有点恐怖!
项目中用到技术:hibernate、redis、kafka、线程池等,启动慢的环境使用的是mysql数据库!
1.最开始查看的启动日志,是在输出:
org.hibernate.id.UUIDHexGenerator : HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead后停滞,等相当长时间后继续输出:
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'taskExecutor'
文章图片
怀疑是创建kafka、线程池等导致耗时,通过去掉相关对象创建,耗时仍无改观!
2. 启动项目,打印日志级别改为debug,查看更详细信息
文章图片
文章图片
发现:大量的alter table 增加外键!奇怪,不是第一次启动项目,mysql库中的表早已创建好,为什么每次都要重复alter?
查看mysql相关表发现无外键,表引擎为MyISAM!此引擎不支持外键!
在使用hibernate自动创建表时,mysql中建表使用的MyISAM引擎,查看配置:
文章图片
dialect
:应使用org.hibernate.dialect.MySQL5InnoDBDialect
如何优化SpringBoot的项目的启动速度 日常开发SpringBoot项目启动类都用@SpringBootApplication
实际上它是下面三个注解的组合
@EnableAutoConfiguration
: enable Spring Boot's auto-configuration mechanism@ComponentScan
: enable@Component
scan on the package where the application is located (see the best practices)@Configuration
: allow to register extra beans in the context or import additional configuration classes
可以用@SpringBootApplication注解下面的属性
exclude
: Exclude the list of classes from the auto configuration.excludeNames
: Exclude the list of fully qualified class names from the auto configuration. This parameter added since spring boot 1.3.0.scanBasePackageClasses
: Provide the list of classes that has to be applied for the @ComponentScan.scanBasePackages
Provide the list of packages that has to be applied for the @ComponentScan. This parameter added since spring boot 1.3.0.
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
推荐阅读
- Activiti(一)SpringBoot2集成Activiti6
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- Hive常见问题汇总
- 17|17 关山松 第二课作业#公众号项目# D20
- 注册分销商的骄傲
- RxJava|RxJava 在Android项目中的使用(一)
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- 靠QQ月入上万灰色暴利偏门的项目
- 如何启动改变