Home > Database > Mysql Tutorial > How to Start Spring Boot Without Database Dependency?

How to Start Spring Boot Without Database Dependency?

Linda Hamilton
Release: 2024-11-11 17:02:02
Original
250 people have browsed it

How to Start Spring Boot Without Database Dependency?

Starting Spring Boot without Database Dependency

Many applications use Spring Boot and Hibernate for data access, but may encounter errors when the database is unavailable during startup. To resolve this issue, follow these steps:

Adjust Connection Settings

In the application.yml file, modify the spring.datasource configuration:

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
Copy after login
  • continueOnError: Allows Spring to continue initializing the application even if the database is unavailable.
  • initialize: Prevents Spring from creating the database during startup.

Adjust Hibernate Settings

In the hibernate configuration within application.yml:

spring:
  ...
  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
  • dialect: Specifies the database dialect for Hibernate.
  • hbm2ddl.auto: Disables automatic database schema updates.
  • use_jdbc_metadata_defaults: Prevents Hibernate from using JDBC metadata to determine database structure.

The above is the detailed content of How to Start Spring Boot 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