0

My tomcat cannot start if DB is down. How i want spring allow to start even the DB is down, and will reconnect the DB once DB its alive?

Im using Spring 4 and BoneCP for the datasource. Below is my jdbc configuration in applicationContext.xml. Im using Tomcat 8.5.

<bean id="defaultDataSource" class="com.jolbox.bonecp.BoneCPDataSource"
    destroy-method="close" p:driverClass="${jdbc.driverClassName}"
    p:jdbcUrl="${jdbc.url}" p:username="${jdbc.user}" p:password="${jdbc.pass}"
    p:maxConnectionsPerPartition="${partition.max.connections}"
    p:minConnectionsPerPartition="${partition.min.connections}"
    p:partitionCount="${partition.count}" p:acquireIncrement="${partition.acquire.incrementcount}"
    p:statementsCacheSize="${statements.cache.size}"
    p:idleMaxAgeInMinutes="${idle.max.age.minutes}" />

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource" ref="defaultDataSource" />
</bean>


<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
</bean>
Sh4m
  • 1,424
  • 12
  • 30

1 Answers1

0

You can set your spring process to start even on database error, if you use spring boot ,you can just set like (doc):

spring.datasource.continue-on-error=true

Even reconnect is not recommend ,you can still do it by set (link here):

spring.datasource.testOnBorrow=true
FisherMartyn
  • 826
  • 1
  • 8
  • 17