升级到 Spring Boot 2.2.2 后应用程序启动缓慢
Posted
技术标签:
【中文标题】升级到 Spring Boot 2.2.2 后应用程序启动缓慢【英文标题】:Slow Application Startup Time After Upgrade to Spring Boot 2.2.2 【发布时间】:2020-04-14 23:54:50 【问题描述】:我将我的应用程序升级到 Spring Boot 2.2.2,现在启动时间在 30 秒范围内。
:: Built with Spring Boot :: 2.2.2.RELEASE
2019-12-23 10:38:06.822 INFO 4669 --- [ restartedMain] c.d.l.i.r.IdeaSubmissionRestApplication : Starting IdeaSubmissionRestApplication on wsm-93.local with PID 4669 (/Users/mhast/Developer/sts_workspaces_4_4_1/dss/ldrd_s/IdeaSubmissionRest/target/classes started by mhast in /Users/mhast/Developer/sts_workspaces_4_4_1/dss/ldrd_s/IdeaSubmissionRest)
2019-12-23 10:38:06.826 INFO 4669 --- [ restartedMain] c.d.l.i.r.IdeaSubmissionRestApplication : The following profiles are active: dev
...
2019-12-23 10:38:08.440 INFO 4669 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8320 (http)
2019-12-23 10:38:08.447 INFO 4669 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-12-23 10:38:08.448 INFO 4669 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2019-12-23 10:38:08.512 INFO 4669 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-23 10:38:08.512 INFO 4669 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1530 ms
2019-12-23 10:38:08.678 INFO 4669 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-12-23 10:38:09.189 INFO 4669 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-12-23 10:38:09.234 INFO 4669 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-12-23 10:38:09.285 INFO 4669 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core 5.4.9.Final
2019-12-23 10:38:09.370 INFO 4669 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations 5.1.0.Final
2019-12-23 10:38:09.456 INFO 4669 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2019-12-23 10:38:37.903 INFO 4669 --- [ restartedMain] org.hibernate.tuple.PojoInstantiator : HHH000182: No default (no-argument) constructor for class: com.desertsky.ldrd.model.entities.FrsFactTableViewId (class must be instantiated by Interceptor)
2019-12-23 10:38:39.038 INFO 4669 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-12-23 10:38:39.043 INFO 4669 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-12-23 10:38:40.109 WARN 4669 --- [ restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
从 10:38:09.456 开始加载 Oracle10gDialect,下一个日志是 28 秒后。
2019-12-23 10:38:09.456 INFO 4669 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2019-12-23 10:38:37.903 INFO 4669 --- [ restartedMain] org.hibernate.tuple.PojoInstantiator : HHH000182: No default (no-argument) constructor for class: com.desertsky.ldrd.model.entities.FrsFactTableViewId (class must be instantiated by Interceptor)
有人知道为什么在升级到 Spring Boot 2.2.2 后,方言加载如此缓慢吗?
【问题讨论】:
【参考方案1】:我在这篇文章中找到了答案。
Very slow Spring Boot application startup
我将此属性添加到我的 application.properties 文件中,我又回到了快速的应用程序启动状态。
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
JBoss Hibernate 文档说:
This setting is used to control whether we should consult the JDBC metadata to determine certain Settings default values when the database may not be available (mainly in tools usage).
【讨论】:
以上是关于升级到 Spring Boot 2.2.2 后应用程序启动缓慢的主要内容,如果未能解决你的问题,请参考以下文章
将 Web 应用升级到 Spring Boot 2.4 后出现 IllegalStateException
Spring Boot - 从 2.2.5 升级到 2.5.7 后,应用程序无法启动
升级到 Spring Boot 2.0.2 后 Spring Security .permitAll() 不再有效
从 Spring Boot 2.1.6 升级到 2.2.2 时,Prometheus 不导出 Kafka Consumer 数据