How to start spring server even if the database is down?

I am using Spring Boot (1.4.7) and 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 the program with errors when the database is disconnected on the Eclipse or Linux server. (The database is not located on the local host.)

When I try to run the program with the database disconnected, print this out.

 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 anyway?

thanks

+11
source share
2 answers

You can install:

 spring.datasource.continue-on-error=true 

in your application. properties.

According to Spring Boot 2.1.8 user manual :

By default, Spring Boot enables the quick-fail feature in the Spring JDBC initializer. This means that if scripts throw exceptions, the application does not start. You can customize this behavior by setting spring.datasource.continue-on-error

+6
source

You need to add

 spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect 

to make it work

+1
source

Source: https://habr.com/ru/post/1270381/


All Articles