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
To access the Relational Database by using JdbcTemplate in Spring Boot application, we need to add the Spring Boot Starter JDBC dependency in our build configuration file. Then, if you @Autowired the JdbcTemplate class, Spring Boot automatically connects the Database and sets the Datasource for the JdbcTemplate object.
The easiest way to test the database connection from Spring boot is to start the application and by checking to debug logs.
Another way to disable the embedded web server in Spring Boot is by using code. We can use either the SpringApplicationBuilder: new SpringApplicationBuilder(MainApplication. class) .
You can set:
spring.sql.init.continue-on-error=true
in your application.properties.
According to the Spring Boot 2.5.5 user guide:
By default, Spring Boot enables the fail-fast feature of its script-based database initializer. This means that, if the scripts cause exceptions, the application fails to start. You can tune that behavior by setting
spring.sql.init.continue-on-error
.
P.S.: Before Spring Boot 2.5, the property was named spring.datasource.continue-on-error
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With