简体   繁体   中英

How to make Spring server to start even if database is down?

I'm using a Spring Boot(1.4.7) & MyBatis.

spring.main1.datasource.url=jdbc:mariadb://192.168.0.11:3306/testdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&socketTimeout=5000&connectTimeout=3000
spring.main1.datasource.username=username
spring.main1.datasource.password=password
spring.main1.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.main1.datasource.tomcat.test-on-borrow=true
spring.main1.datasource.tomcat.test-while-idle=true
spring.main1.datasource.tomcat.validation-query=SELECT 1
spring.main1.datasource.tomcat.validation-query-timeout=5000
spring.main1.datasource.tomcat.validation-interval=5000
spring.main1.datasource.tomcat.max-wait=5000
spring.main1.datasource.continue-on-error=true

I cannot start program with errors when database is disconnected on Eclipse or Linux server. (Database is not located on localhost.)

When I try to start program with disconnected database, print this.

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Stopping service [Tomcat]
Application startup failed

Is there any way?

Thanks

I'm using a Spring Boot(1.4.7) & MyBatis.

spring.main1.datasource.url=jdbc:mariadb://192.168.0.11:3306/testdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&socketTimeout=5000&connectTimeout=3000
spring.main1.datasource.username=username
spring.main1.datasource.password=password
spring.main1.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.main1.datasource.tomcat.test-on-borrow=true
spring.main1.datasource.tomcat.test-while-idle=true
spring.main1.datasource.tomcat.validation-query=SELECT 1
spring.main1.datasource.tomcat.validation-query-timeout=5000
spring.main1.datasource.tomcat.validation-interval=5000
spring.main1.datasource.tomcat.max-wait=5000
spring.main1.datasource.continue-on-error=true

I cannot start program with errors when database is disconnected on Eclipse or Linux server. (Database is not located on localhost.)

When I try to start program with disconnected database, print this.

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Stopping service [Tomcat]
Application startup failed

Is there any way?

Thanks

I'm using a Spring Boot(1.4.7) & MyBatis.

spring.main1.datasource.url=jdbc:mariadb://192.168.0.11:3306/testdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&socketTimeout=5000&connectTimeout=3000
spring.main1.datasource.username=username
spring.main1.datasource.password=password
spring.main1.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.main1.datasource.tomcat.test-on-borrow=true
spring.main1.datasource.tomcat.test-while-idle=true
spring.main1.datasource.tomcat.validation-query=SELECT 1
spring.main1.datasource.tomcat.validation-query-timeout=5000
spring.main1.datasource.tomcat.validation-interval=5000
spring.main1.datasource.tomcat.max-wait=5000
spring.main1.datasource.continue-on-error=true

I cannot start program with errors when database is disconnected on Eclipse or Linux server. (Database is not located on localhost.)

When I try to start program with disconnected database, print this.

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Stopping service [Tomcat]
Application startup failed

Is there any way?

Thanks

I'm using a Spring Boot(1.4.7) & MyBatis.

spring.main1.datasource.url=jdbc:mariadb://192.168.0.11:3306/testdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&socketTimeout=5000&connectTimeout=3000
spring.main1.datasource.username=username
spring.main1.datasource.password=password
spring.main1.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.main1.datasource.tomcat.test-on-borrow=true
spring.main1.datasource.tomcat.test-while-idle=true
spring.main1.datasource.tomcat.validation-query=SELECT 1
spring.main1.datasource.tomcat.validation-query-timeout=5000
spring.main1.datasource.tomcat.validation-interval=5000
spring.main1.datasource.tomcat.max-wait=5000
spring.main1.datasource.continue-on-error=true

I cannot start program with errors when database is disconnected on Eclipse or Linux server. (Database is not located on localhost.)

When I try to start program with disconnected database, print this.

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Stopping service [Tomcat]
Application startup failed

Is there any way?

Thanks

I'm using a Spring Boot(1.4.7) & MyBatis.

spring.main1.datasource.url=jdbc:mariadb://192.168.0.11:3306/testdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&socketTimeout=5000&connectTimeout=3000
spring.main1.datasource.username=username
spring.main1.datasource.password=password
spring.main1.datasource.driverClassName=org.mariadb.jdbc.Driver
spring.main1.datasource.tomcat.test-on-borrow=true
spring.main1.datasource.tomcat.test-while-idle=true
spring.main1.datasource.tomcat.validation-query=SELECT 1
spring.main1.datasource.tomcat.validation-query-timeout=5000
spring.main1.datasource.tomcat.validation-interval=5000
spring.main1.datasource.tomcat.max-wait=5000
spring.main1.datasource.continue-on-error=true

I cannot start program with errors when database is disconnected on Eclipse or Linux server. (Database is not located on localhost.)

When I try to start program with disconnected database, print this.

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=192.168.0.11)(port=3306)(type=master) : connect timed out
Stopping service [Tomcat]
Application startup failed

Is there any way?

Thanks

If the tips above didn't help and you use jpa, then set

spring.jpa.hibernate.ddl-auto=none

it worked for me.

I have some similar case here but my application is connecting to two databases. I want to make it up and running if first database is down. so it should connect to second database. Both DBs are different ie 1. Postgres and 2. MS SQL. But Postgres db does not have much dependency for application. But MS SQL DB is mandatory for application. Can someone help on this.

Below are the configurations in .yml file.

Configuration Image

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