<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<!-- 通过注解配置事务 -->
    <tx:annotation-driven proxy-target-class="true"/>

	<!-- 解析properties，创建dataSource -->
	<bean id="dataSourceService" class="com.mossle.core.jdbc.DataSourceServiceFactoryBean">
		<property name="properties" ref="applicationProperties"/>
		<property name="defaultPrefix" value="db"/>
	</bean>

	<!-- 默认的dataSource -->
	<bean id="dataSource" factory-bean="dataSourceService" factory-method="getDataSource"/>

	<!-- jdbcTemplate -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" depends-on="databaseMigrator">
        <property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 自动初始化数据库 -->
	<bean id="databaseMigrator" class="com.mossle.core.dbmigrate.DatabaseMigrator" depends-on="hsqldbServer">
		<property name="dataSource" ref="dataSource"/>
		<property name="enabled" value="${dbmigrate.enabled}"/>
		<property name="clean" value="${dbmigrate.clean}"/>
	</bean>

	<!-- 测试用的hsqldb数据库 -->
	<bean id="hsqldbServer" class="com.mossle.simulator.hsqldb.HsqldbServer">
		<property name="enabled" value="${hsqldb.enabled}"/>
		<property name="username" value="${hsqldb.username}"/>
		<property name="password" value="${hsqldb.password}"/>
		<property name="port" value="${hsqldb.port}"/>
		<property name="path" value="${hsqldb.path}"/>
		<property name="databaseName" value="${hsqldb.databaseName}"/>
	</bean>
</beans>
