简体   繁体   中英

Spring app should start even though DB is down

I have a spring app which do minimal operations with DB. And I have a requirment that my application should run under the absence of DB(or when db is down).Below is my datasource configuration.

<bean id="dt31DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" depends-on="systemPropertyInitializer"
                      p:driverClass="${dt31.driver_class}"
                      p:jdbcUrl="${dt31.url}"
                      p:user="${dt31.username}"
                      p:password="${dt31.password}"
                      p:idleConnectionTestPeriod="1000"
                      p:maxPoolSize="4"
                      p:minPoolSize="2"
                      p:maxIdleTime="2000"
                      p:unreturnedConnectionTimeout="600"
                      p:contextClassLoaderSource="library"
                      p:privilegeSpawnedThreads="true"
                      p:initialize=false
                      />

    <bean id="dt31SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dt31DataSource"/>
        <property name="packagesToScan" value="com.t22.dt31"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    ${dt31.dialect}
                </prop>
                <prop key="hibernate.show_sql">
                    false
                </prop>
                <prop key="hibernate.hbm2ddl.auto">
                    update
                </prop>
            </props>
        </property>
    </bean>

I found a page in google,saying to use "initialize: false" in spring data source configuration.But I am using "ComboPooledDataSource" datasource which does not have this property.Is there any other way to achieve this ?

The application service layer can operate with two DAO layers (file system and database), so when the DB is down you catch the connection acquire exception and switch to the file system instead.

Having two sources of truth is going to make it difficult to preserve consistency across two different data sources, especially if one resource is not available.

When both resources are available you can use XADisk and Bitronix for XADataSource and JTA transaction management.

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