Home > Database > Mysql Tutorial > body text

How to Start a Spring-Boot App Without Database Dependency?

Mary-Kate Olsen
Release: 2024-11-07 21:00:04
Original
657 people have browsed it

How to Start a Spring-Boot App Without Database Dependency?

How to Start Spring-Boot App Without Database Dependency

For applications employing Spring-boot, Hibernate4, and MySQL, a situation may arise where the sprint-boot app needs to initialize even with an unavailable database. By default, an exception occurs when attempting to start the app. Upon investigation, it appears this issue stems from the "hibernate.temp.use_jdbc_metadata_defaults" property.

Although setting this property in the "application.yml" of Spring Boot may seem logical, it doesn't reflect at runtime. To resolve this, consider these settings:

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

The above settings enable the application to:

  • Start even when the database is down.
  • Automatically connect upon database availability, eliminating the need for redeployment or restarting the web server.
  • Handle database outages and reconnections gracefully.

The above is the detailed content of How to Start a Spring-Boot App Without Database Dependency?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template