简体   繁体   中英

How to keep Spring boot application running when Oracle connection fails

I have an application written in Spring boot version 2.7.2 and connected to an Oracle database. How can my application still run even if it can't connect to the database (wrong url or dead database)

  • configuration:
spring:
  main:
    web-application-type: none
    log-startup-info: true
  profiles:
    active: production
  sql:
    init:
      continue-on-error: true
  datasource:
    url: jdbc:oracle:thin:@127.0.0.1:1521:thanbv
    username: thanbv

The application will not be able to run when my database has been shut down.

 Failed to obtain JDBC Connection; nested exception is java.sql.SQLException
  • I tried adding this configuration but it still doesn't work:
spring:
  sql:
    init:
      continue-on-error: true

How do I keep my application running regardless of whether the connection is successful with the database?

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

it works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM