Spring Boot + HikariCP - 自动配置DataSource的非确定性故障

时间:2018-05-18 17:59:15

标签: spring spring-boot spring-data-jpa hikaricp

在我的本地计算机上,当我从IntelliJ运行我的一个Spring Boot 2.0.0应用程序时,应用程序会定期无法启动,并且控制台中会显示以下消息:

  

应用程序无法启动

     

说明

     

无法自动配置DataSource:未指定“spring.datasource.url”,也无法自动配置嵌入数据源。

     

原因:无法确定合适的驱动器类

当我收到此错误时,如果我再次尝试运行该应用程序,它将(有时)启动。这种行为似乎是不确定的。有时应用程序会在第一次尝试时启动,有时需要连续几次尝试。

编辑---------------------------------------------- ------------------------------

  

错误似乎是由于应用程序无法确定哪些配置文件处于活动状态而导致的。当应用程序无法启动时,Spring日志记录输出指出“没有活动的配置文件集,回退到默认配置文件:默认”。当应用程序成功启动时,日志记录输出将显示“以下配置文件处于活动状态:local,permitall”,这些是我在application.properties中设置为活动的配置文件。

     

不幸的是,Spring是否确定启动时哪个配置文件处于活动状态对我来说是一堆骰子。

----------------------------------------------- -----------------------------------

我的应用程序配置为使用spring-boot-starter-data-jpa并连接到Postgres数据库。对于连接池,我使用HikariCP 2.7.8。

控制台错误(见下文)暗示Hikari无法加载数据源。由于此错误是非确定性的,可能取决于Spring在启动期间创建bean的顺序?

spring.datasource.url属性在我的本地应用程序属性文件中定义。应用程序属性文件将spring active profile属性设置为local。

这是我的application.properties文件

spring.profiles.active=local,permitall 
management.endpoints.web.base-path=/
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

这是我的application-local.properties

spring.datasource.url=jdbc:postgresql://localhost/vms?currentSchema=vms
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update

我没有找到失败或成功的模式。任何有关解决或解决此问题的想法都表示赞赏。

控制台错误消息

  

2018-05-18 13:53:49.667 ERROR 16228 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter:启动Tomcat上下文时出错。例外:org.springframework.beans.factory.BeanCreationException。消息:创建在类路径资源

中定义名称为“servletEndpointRegistrar”的bean时出错      

[org / springframework / boot / actuate / autoconfigure / endpoint / web / ServletEndpointManagementContextConfiguration.class]:通过工厂方法进行Bean实例化失败;

     

嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:工厂方法'servletEndpointRegistrar'抛出异常;

     

嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'healthEndpoint'的bean时出错[org / springframework / boot / actuate / autoconfigure / health / HealthEndpointConfiguration.class]:Bean实例化通过工厂方法失败;

     

嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.health.HealthEndpoint]:工厂方法'healthEndpoint'抛出异常;

     

嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration'的bean时出错:通过构造函数的Bean实例化失败;

     

嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration $$ EnhancerBySpringCGLIB $$ 61a24aeb]:构造函数抛出异常;

     

嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'dataSource'的bean时出错[org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]:Bean实例化通过工厂方法失败;

     

嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'抛出异常;

     

嵌套异常是org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException:无法确定合适的驱动程序类

0 个答案:

没有答案