美文网首页
2018-11-27 springBoot启动慢

2018-11-27 springBoot启动慢

作者: HelloWide | 来源:发表于2018-11-27 11:13 被阅读0次

    某次在内网(无互联网访问),centos7.3 tomcat7部署boot war包是发现,应用每次卡在:[ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect,时长达10多分钟,使用idea启动boot内嵌tomcat启动时打印如下:

    2018-11-27 10:58:39.542 INFO 10488 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect

    2018-11-27 10:58:47.689  INFO 10488 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

    研究发现,boot-start包内部嵌套了hibernate,Hibernate默认是使用jdbc方式来取的,而工程使用的是mybatis+druid方式,jdbc自然获取不到连接;通过在application.properties配置:spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false即可跳过jdbc hibernate连接,测试验证后再linux环境下启动无卡顿;

    boot简单灵活性建立在封装了多种常用组件基础之上,例如hibernate jpa核心服务,该问题切入点可以查看

    package org.hibernate.engine.jdbc.env.internal;

    ...

    public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEnvironment> {

    @Override

    public JdbcEnvironment initiateService(Map configurationValues, ServiceRegistryImplementor registry) {

      final DialectFactory dialectFactory = registry.getService( DialectFactory.class );

      // 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.

    // The need for it is intended to be alleviated with future development, thus it is

    // not defined as an Environment constant...

    //

    // it is used to control whether we should consult the JDBC metadata to determine

    // certain Settings default values; it is useful to *not* do this when the database

    // may not be available (mainly in tools usage).

      boolean useJdbcMetadata = ConfigurationHelper.getBoolean(

            "hibernate.temp.use_jdbc_metadata_defaults",

            configurationValues,

    true

      );

    ...

    相关调用链分析可以提供IDE分析即可;

    也可以通过springboot删除hibernate服务:

    <dependency>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-data-jpa</artifactId>

      <!--排除Hibernate相关依赖-->

      <exclusions>

        <exclusion>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-core</artifactId>

        </exclusion>

        <exclusion>

          <groupId>org.hibernate</groupId>

          <artifactId>hibernate-entitymanager</artifactId>

        </exclusion>

      </exclusions>

    </dependency>

    相关文章

      网友评论

          本文标题:2018-11-27 springBoot启动慢

          本文链接:https://www.haomeiwen.com/subject/iftgqqtx.html