【发布时间】:2017-01-20 05:38:07
【问题描述】:
我需要将我的 Spring 应用程序数据库从 MySql 迁移到 HSQL 数据库。我在我的 xml 文件中配置了 hsql db 详细信息,并且能够运行 sql 文件并成功连接到它。听到问题是,当我重新启动我的 tomcat 服务器时,正在创建新数据库并且正在删除旧数据库。我正在查看我存储在表中的所有数据。我怎样才能在战争部署时只为 HSQL 创建一次数据库,或者每次 tomcat 重启时只创建一次。
听到的是我的配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd">
<jdbc:embedded-database id="dbcpDataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql"/>
</jdbc:embedded-database>
<tx:annotation-driven/>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
<property name="maxActive" value="100000"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="16000"/>
<property name="minIdle" value="0"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dbcpDataSource"/>
<property name="packagesToScan" value="com.design.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
<property name="exposeTransactionAwareSessionFactory"><value>false</value></property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
【问题讨论】: