spring-config-dao.xml 5.06 KB
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    		http://www.springframework.org/schema/beans/spring-beans.xsd
       		http://www.springframework.org/schema/context 
     		http://www.springframework.org/schema/context/spring-context.xsd
     		http://www.springframework.org/schema/aop
			http://www.springframework.org/schema/aop/spring-aop.xsd"
       default-autowire="byName">

	<context:component-scan base-package="com.dili.titan.dao" />

    <bean id="baseDataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="filters" value="stat"/>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <property name="maxWait" value="${jdbc.maxWait}"/>
        <property name="minIdle" value="${jdbc.minIdle}"/>
        <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
        <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
        <property name="validationQuery" value="SELECT now()"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="poolPreparedStatements" value="${jdbc.poolPreparedStatements}"/>
        <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}"/>
    </bean>

    <bean id="masterDataSource" parent="baseDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${master.jdbcUrl}"/>
        <property name="username" value="${master.jdbc.username}"/>
        <property name="password" value="${master.jdbc.password}"/>
    </bean>

    <bean id="slaveDataSource" parent="baseDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${slave.jdbcUrl}"/>
        <property name="username" value="${slave.jdbc.username}"/>
        <property name="password" value="${slave.jdbc.password}"/>
    </bean>

    <bean id="dynamicDataSource" class="com.dili.titan.common.datasource.DynamicDataSource">
        <property name="masterDataSources">
            <map key-type="java.lang.String">
                <!-- write  key从1,2,3...按顺序开始命名-->
                <entry key="master1" value-ref="masterDataSource"/>
            </map>

        </property>
        <property name="slaveDataSources">
            <map key-type="java.lang.String">
                <!-- read key从1,2,3...按顺序开始命名-->
                <entry key="slave1" value-ref="slaveDataSource"/>
            </map>

        </property>
        <property name="defaultTargetDataSource" ref="masterDataSource"/>
    </bean>

    <bean id="manyDataSourceAspect" class="com.dili.titan.common.datasource.DataSourceAspect">
        <property name="mastersCount" value="1"/>
   </bean>
    <aop:config>
        <aop:aspect id="c" ref="manyDataSourceAspect">
            <aop:pointcut id="tx" expression="@within(com.dili.titan.common.datasource.DynamicSource)"/>
            <!--<aop:before pointcut-ref="tx" method="before"/>-->
            <!--<aop:before pointcut-ref="tx" method="after"/>-->
            <aop:around pointcut-ref="tx" method="around"/>
        </aop:aspect>
    </aop:config>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dynamicDataSource" />
	</bean>

	<!-- 集成Mybatis -->
	<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dynamicDataSource" />
		<property name="configLocation" value="classpath:sqlmap-config.xml" />
	</bean>

	<bean id="sqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sessionFactory" />
	</bean>
	<bean id="batchSqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sessionFactory" />
		<constructor-arg index="1" value="BATCH" />
	</bean>
	
	<bean id="productDescDao" class="com.dili.titan.dao.impl.ProductDescDaoImpl">
		<property name="tableName" value="agriez_titan"/>
		<property name="family" value="f1" />
		<property name="qualifier" value="product_desc" />
		<property name="suffix" value="_product_desc" />
	</bean>

    <bean id="templeteDescDao" class="com.dili.titan.dao.impl.TempleteDescDaoImpl">
        <property name="tableName" value="agriez_titan_templeteDesc"/>
        <property name="family" value="f2" />
        <property name="qualifier" value="templete_desc" />
        <property name="suffix" value="_templete_desc" />
    </bean>
	
</beans>