How to start spring-boot app without depending on Database?

被刻印的时光 ゝ 提交于 2019-11-27 02:53:08

It was indeed a tough nut to crack.

After lot and lot of research and actually debugging the spring-boot, spring, hibernate, tomcat pool, etc to get it done.

I do think that it will save lot of time for people trying to achieve this type of requirement.

Below are the settings required to achieve the following requirement

  1. Spring boot apps will start fine even if DB is down or there is no DB.
  2. Apps will pick up the connections on the fly as DB comes up which means there is no need to restart the web server or redeploy the apps.
  3. There is no need to start the tomcat or redeploy the apps, if DB goes down from running state and comes up again.

application.yml :

spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/schema
    username: root
    password: root
    continueOnError: true
    initialize: false
    initialSize: 0
    timeBetweenEvictionRunsMillis: 5000
    minEvictableIdleTimeMillis: 5000
    minIdle: 0

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: none
      naming_strategy: org.hibernate.cfg.DefaultNamingStrategy
    properties:
      hibernate:   
        dialect: org.hibernate.dialect.MySQL5Dialect
        hbm2ddl:
          auto: none
        temp:
          use_jdbc_metadata_defaults: false

I am answering here and will close the issue that you have cross-posted

Any "native" property of the JPA implementation (Hibernate) can be set using the spring.jpa.properties prefix as explained here

I haven't looked much further in the actual issue here but to answer this particular question, you can set that hibernate key as follows

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults

Adding this alone worked for me:

spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.Oracle10gDialect

Just replace the last part with your database dialect.

Add following config should be work:

spring.jpa.database-platform: org.hibernate.dialect.MySQL5Dialect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!