Authored by DengXinFei

mybaties重构

... ... @@ -5,7 +5,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>yoho-starter</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-unions</artifactId>
... ...
... ... @@ -39,7 +39,7 @@ public class DingdangServiceImpl implements DingdangService {
@Resource
IUnionsActiveRecordDAO unionsActiveRecordDAO;
private static final String unions_KEY = "unions_KEY_";
private static final String unions_KEY = "yh:unions:dingdang_";
@Override
public UnionResponseBO addUnion(AddUnionRequestBO request) throws ServiceException {
... ...
... ... @@ -21,7 +21,7 @@
<mvc:annotation-driven />
<!-- 装在properties文件 -->
<context:property-placeholder location="classpath*:jdbc.properties,classpath*:config.properties,classpath*:zookeeper.properties" />
<context:property-placeholder location="classpath*:jdbc.properties,classpath*:config.properties" />
<!-- <bean id="restServiceBeanRegistry" class="com.yoho.core.rest.spring.RestServiceBeanRegistry">
<property name="registry" ref="serviceRegistry"></property>
</bean> -->
... ...
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<!-- yoho_passport 数据源 -->
<bean id="yohobuylogsMasterDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mysql.driver}" />
<property name="url" value="${jdbc.mysql.yohopassport.master.url}" />
<property name="username" value="${jdbc.mysql.yohopassport.username}" />
<property name="password" value="${jdbc.mysql.yohopassport.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${jdbc.mysql.initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${jdbc.mysql.maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${jdbc.mysql.minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${jdbc.mysql.maxWait}"></property>
<!--定时对线程池中的链接进行校验 -->
<property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>
<property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>
<property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>
<property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>
</bean>
<bean id="yohobuylogsSlaveDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mysql.driver}" />
<property name="url" value="${jdbc.mysql.yohopassport.slave.url}" />
<property name="username" value="${jdbc.mysql.yohopassport.username}" />
<property name="password" value="${jdbc.mysql.yohopassport.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${jdbc.mysql.initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${jdbc.mysql.maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${jdbc.mysql.minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${jdbc.mysql.maxWait}"></property>
<!--定时对线程池中的链接进行校验 -->
<property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>
<property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>
<property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>
<property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>
</bean>
<bean id="dynamicDataSource" class="com.yoho.core.dal.datasource.DynamicDataSource">
<property name="defaultTargetDataSource" ref="yohobuylogsMasterDataSource" />
<property name="targetDataSources">
<map>
<entry key="yohobuylogsMasterDataSource" value-ref="yohobuylogsMasterDataSource" />
</map>
</property>
</bean>
<bean id="multipleDataSourceRouter" class="com.yoho.core.dal.datasource.MultiDataSourceRouter">
<property name="defaultDBCluster" value="yohobuylogsDbCluster" />
<property name="readOnlyInSlave" value="${jdbc.mysql.readonlyinslave:false}" />
<property name="dbClusterSet">
<map>
<entry key="yohobuylogsDbCluster" value="yohobuylogsMasterDataSource,yohobuylogsMasterDataSource" />
</map>
</property>
<property name="daoDbClusterMap">
<map>
</map>
</property>
</bean>
<bean id="dataSourceMethodInterceptor" class="com.yoho.core.dal.datasource.DataSourceMethodInterceptor">
</bean>
<aop:config>
<aop:pointcut id="daoPoint" expression="execution(* com.yoho.*.dal.*.*(..)) " />
<aop:advisor pointcut-ref="daoPoint" advice-ref="dataSourceMethodInterceptor" />
</aop:config>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dynamicDataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:META-INF/mybatis/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yoho.*.dal" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
</beans>
\ No newline at end of file
#memcached
cache.servers.memcached.address=192.168.102.162:32768
####暂时不使用,待到订单上线的时候恢复使用#########
#MQ
rabbit.mq.host=192.168.102.162
rabbit.mq.port=32810
... ...
datasources:
yoho_passport:
servers:
- 192.168.50.69:9980
- 192.168.102.219:3306
username: yh_test
password: 9nm0icOwt6bMHjMusIfMLw==
readOnlyInSlave: true
\ No newline at end of file
... ...
jdbc.mysql.driver=com.mysql.jdbc.Driver
#定义初始连接数
jdbc.mysql.initialSize=0
#定义最大连接数
jdbc.mysql.maxActive=80
#定义最大空闲
jdbc.mysql.maxIdle=60
#定义最小空闲
jdbc.mysql.minIdle=10
#定义最长等待时间
jdbc.mysql.maxWait=10000
jdbc.mysql.testWhileIdle=true
jdbc.mysql.timeBetweenEvictionRunsMillis=2000
jdbc.mysql.validationQuery=select 1
jdbc.mysql.testOnBorrow=true
jdbc.mysql.testOnReturn=true
#读操作是否只在从库
jdbc.mysql.readonlyinslave=false
#yoho_passport读写数据分离
jdbc.mysql.yohopassport.master.url=jdbc:mysql://192.168.50.69:9980/yoho_passport
jdbc.mysql.yohopassport.slave.url=jdbc:mysql://192.168.102.219:3306/yoho_passport
jdbc.mysql.yohopassport.username=yh_test
jdbc.mysql.yohopassport.password=yh_test
#memcached
cache.servers.memcached.address=${cache.servers.union.address}
####暂时不使用,待到订单上线的时候恢复使用#########
#MQ
rabbit.mq.host=${rabbit.mq.host}
rabbit.mq.port=${rabbit.mq.port}
... ...
datasources:
yoho_passport:
servers:
- ${jdbc.mysql.yohopassport.master}
- ${jdbc.mysql.yohopassport.slave}
username: ${jdbc.mysql.yohopassport.username}
password: ${jdbc.mysql.yohopassport.password}
\ No newline at end of file
... ...
... ... @@ -3,7 +3,7 @@
<display-name>YohoBuy-Resources Service</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/spring*.xml</param-value>
<param-value>classpath*:META-INF/spring/spring-mybatis-datasource.xml, classpath*:META-INF/spring/spring*.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
... ...