?????????????????漰??????????????????????????????????????????????
????1????????????????????????????????????????????????????????????????????????????????????????????????????????μ??????????????
????2?????????????????master-slave????????????mysql????? master-master?????????ж??slave?????????MHA????master-slave?????
??????????????? Spring ????????????????????????????????????????????????
????1. ????spring?????????????????????
??????????????????????????????????????????????spring???????????????????????????????????????????????????
<context:component-scan base-package="net.aazj.service??net.aazj.aop" />
<context:component-scan base-package="net.aazj.aop" />
<!-- ??????????? -->
<context:property-placeholder location="classpath:config/db.properties" />
<!-- ????????? -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
<!-- ??????????С -->
<property name="initialSize" value="0" />
<!-- ????????????????? -->
<property name="maxActive" value="20" />
<!-- ????????? -->
<property name="maxIdle" value="20" />
<!-- ?????С???? -->
<property name="minIdle" value="0" />
<!-- ????????????? -->
<property name="maxWait" value="60000" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:config/mybatis-config.xml" />
<property name="mapperLocations" value="classpath*:config/mappers/**/*.xml" />
</bean>
<!-- Transaction manager for a single JDBC DataSource -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- ???annotation???????? -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="net.aazj.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!-- Enables the use of the @AspectJ style of Spring AOP -->
<aop:aspectj-autoproxy/>
<!-- ===============????????????????=============== -->
<bean name="dataSource_2" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc_url_2}" />
<property name="username" value="${jdbc_username_2}" />
<property name="password" value="${jdbc_password_2}" />
<!-- ??????????С -->
<property name="initialSize" value="0" />
<!-- ????????????????? -->
<property name="maxActive" value="20" />
<!-- ????????? -->
<property name="maxIdle" value="20" />
<!-- ?????С???? -->
<property name="minIdle" value="0" />
<!-- ????????????? -->
<property name="maxWait" value="60000" />
</bean>
<bean id="sqlSessionFactory_slave" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_2" />
<property name="configLocation" value="classpath:config/mybatis-config-2.xml" />
<property name="mapperLocations" value="classpath*:config/mappers2/**/*.xml" />
</bean>
<!-- Transaction manager for a single JDBC DataSource -->
<bean id="transactionManager_2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_2" />
</bean>
<!-- ???annotation???????? -->
<tx:annotation-driven transaction-manager="transactionManager_2" />
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="net.aazj.mapper2" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_2"/>
</bean>