Home > Database > Mysql Tutorial > body text

How to Start a Spring Boot App Without a Database: Overcoming the `hibernate.temp.use_jdbc_metadata_defaults` Issue?

DDD
Release: 2024-11-08 04:57:02
Original
687 people have browsed it

How to Start a Spring Boot App Without a Database: Overcoming the `hibernate.temp.use_jdbc_metadata_defaults` Issue?

How to Start Spring-Boot App Without Database Dependency

Problem

Spring-boot applications dependent on a database may encounter issues starting when the database is down. This results in an exception related to the hibernate.temp.use_jdbc_metadata_defaults property. Setting this property in the application.yml file doesn't reflect at runtime.

Solution

To start a spring-boot application even without a database, configure the following settings in 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
Copy after login

Key Configuration:

  • continueOnError: true - Continues even if database connection fails.
  • initialize: false - Doesn't initialize connection pool on startup.
  • initialSize: 0 - Initializes an empty connection pool.
  • hibernate.temp.use_jdbc_metadata_defaults: false - Specifies that the database schema shouldn't be automatically acquired from the JDBC metadata.

With these configurations, the spring-boot application will start without the database, initialize the connection when the database becomes available, and seamlessly handle database outages without requiring a restart or redeployment.

The above is the detailed content of How to Start a Spring Boot App Without a Database: Overcoming the `hibernate.temp.use_jdbc_metadata_defaults` Issue?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template