Spring Boot应用程序启动非常慢 [英] Very slow Spring Boot application startup

查看:1235
本文介绍了Spring Boot应用程序启动非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Spring Boot应用程序,该应用程序连接到PostgreSQL数据库并用作JSON服务。启动不知何故变得非常缓慢,请参见时间10:37:10和10:38:00:

I have a simple Spring Boot application that connects to a PostgreSQL database and serves as a JSON service. Somehow the startup has become very slow, see timings 10:37:10 and 10:38:00:

2015-05-09 10:37:09.649  INFO 20880 --- [lication.main()] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-05-09 10:37:09.651  INFO 20880 --- [lication.main()] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-05-09 10:37:09.767  INFO 20880 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2015-05-09 10:37:09.767  INFO 20880 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2970 ms
2015-05-09 10:37:09.979  INFO 20880 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2015-05-09 10:37:09.985  INFO 20880 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-05-09 10:37:10.105  INFO 20880 --- [lication.main()] o.s.j.d.DriverManagerDataSource          : Loaded JDBC driver: org.postgresql.Driver
2015-05-09 10:37:10.214  INFO 20880 --- [lication.main()] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-05-09 10:37:10.233  INFO 20880 --- [lication.main()] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2015-05-09 10:37:10.585  INFO 20880 --- [lication.main()] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.8.Final}
2015-05-09 10:37:10.587  INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2015-05-09 10:37:10.589  INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2015-05-09 10:37:10.968  INFO 20880 --- [lication.main()] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-05-09 10:38:00.023  INFO 20880 --- [lication.main()] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2015-05-09 10:38:00.041  INFO 20880 --- [lication.main()] o.h.e.jdbc.internal.LobCreatorBuilder    : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2015-05-09 10:38:00.274  INFO 20880 --- [lication.main()] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory

任何有什么想法吗?我可以做些什么来诊断问题?

Any thoughts? Is there anything I can do to diagnose the problem?

推荐答案

对于Spring Boot,您可以在application.properties文件中进行设置:

For Spring Boot you can set this in your application.properties file:

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

我还发现我需要设置另一个属性,否则会收到错误消息 org.hibernate.HibernateException:当'hibernate.dialect时,对DialectResolutionInfo的访问不能为null ' 没有设置。要纠正这一点,我设置了此属性:

I also found that I needed to set another property or I would get the error "org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set". To rectify that I set this property:

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

这将我们的启动时间从大约100秒减少到12秒。

This reduced our startup time from about 100 seconds down to 12.

这篇关于Spring Boot应用程序启动非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆