Authored by DengXinFei

mybaties重构

@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <parent> 5 <parent>
6 <groupId>com.yoho</groupId> 6 <groupId>com.yoho</groupId>
7 <artifactId>yoho-starter</artifactId> 7 <artifactId>yoho-starter</artifactId>
8 - <version>1.0.2-SNAPSHOT</version> 8 + <version>1.0.4-SNAPSHOT</version>
9 </parent> 9 </parent>
10 <groupId>com.yoho.dsf</groupId> 10 <groupId>com.yoho.dsf</groupId>
11 <artifactId>yoho-unions</artifactId> 11 <artifactId>yoho-unions</artifactId>
@@ -39,7 +39,7 @@ public class DingdangServiceImpl implements DingdangService { @@ -39,7 +39,7 @@ public class DingdangServiceImpl implements DingdangService {
39 @Resource 39 @Resource
40 IUnionsActiveRecordDAO unionsActiveRecordDAO; 40 IUnionsActiveRecordDAO unionsActiveRecordDAO;
41 41
42 - private static final String unions_KEY = "unions_KEY_"; 42 + private static final String unions_KEY = "yh:unions:dingdang_";
43 43
44 @Override 44 @Override
45 public UnionResponseBO addUnion(AddUnionRequestBO request) throws ServiceException { 45 public UnionResponseBO addUnion(AddUnionRequestBO request) throws ServiceException {
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 21
22 <mvc:annotation-driven /> 22 <mvc:annotation-driven />
23 <!-- 装在properties文件 --> 23 <!-- 装在properties文件 -->
24 - <context:property-placeholder location="classpath*:jdbc.properties,classpath*:config.properties,classpath*:zookeeper.properties" /> 24 + <context:property-placeholder location="classpath*:jdbc.properties,classpath*:config.properties" />
25 <!-- <bean id="restServiceBeanRegistry" class="com.yoho.core.rest.spring.RestServiceBeanRegistry"> 25 <!-- <bean id="restServiceBeanRegistry" class="com.yoho.core.rest.spring.RestServiceBeanRegistry">
26 <property name="registry" ref="serviceRegistry"></property> 26 <property name="registry" ref="serviceRegistry"></property>
27 </bean> --> 27 </bean> -->
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<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"  
3 - xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"  
4 - xsi:schemaLocation="http://www.springframework.org/schema/beans  
5 - http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
6 - http://www.springframework.org/schema/context  
7 - http://www.springframework.org/schema/context/spring-context-3.1.xsd  
8 - http://www.springframework.org/schema/mvc  
9 - http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  
10 - http://www.springframework.org/schema/aop  
11 - http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">  
12 -  
13 - <!-- yoho_passport 数据源 -->  
14 - <bean id="yohobuylogsMasterDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
15 - <property name="driverClassName" value="${jdbc.mysql.driver}" />  
16 - <property name="url" value="${jdbc.mysql.yohopassport.master.url}" />  
17 - <property name="username" value="${jdbc.mysql.yohopassport.username}" />  
18 - <property name="password" value="${jdbc.mysql.yohopassport.password}" />  
19 - <!-- 初始化连接大小 -->  
20 - <property name="initialSize" value="${jdbc.mysql.initialSize}"></property>  
21 - <!-- 连接池最大数量 -->  
22 - <property name="maxActive" value="${jdbc.mysql.maxActive}"></property>  
23 - <!-- 连接池最大空闲 -->  
24 - <property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>  
25 - <!-- 连接池最小空闲 -->  
26 - <property name="minIdle" value="${jdbc.mysql.minIdle}"></property>  
27 - <!-- 获取连接最大等待时间 -->  
28 - <property name="maxWait" value="${jdbc.mysql.maxWait}"></property>  
29 - <!--定时对线程池中的链接进行校验 -->  
30 - <property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>  
31 - <property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>  
32 - <property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>  
33 - <property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>  
34 - <property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>  
35 -  
36 - </bean>  
37 - <bean id="yohobuylogsSlaveDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
38 - <property name="driverClassName" value="${jdbc.mysql.driver}" />  
39 - <property name="url" value="${jdbc.mysql.yohopassport.slave.url}" />  
40 - <property name="username" value="${jdbc.mysql.yohopassport.username}" />  
41 - <property name="password" value="${jdbc.mysql.yohopassport.password}" />  
42 - <!-- 初始化连接大小 -->  
43 - <property name="initialSize" value="${jdbc.mysql.initialSize}"></property>  
44 - <!-- 连接池最大数量 -->  
45 - <property name="maxActive" value="${jdbc.mysql.maxActive}"></property>  
46 - <!-- 连接池最大空闲 -->  
47 - <property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>  
48 - <!-- 连接池最小空闲 -->  
49 - <property name="minIdle" value="${jdbc.mysql.minIdle}"></property>  
50 - <!-- 获取连接最大等待时间 -->  
51 - <property name="maxWait" value="${jdbc.mysql.maxWait}"></property>  
52 - <!--定时对线程池中的链接进行校验 -->  
53 - <property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>  
54 - <property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>  
55 - <property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>  
56 - <property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>  
57 - <property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>  
58 - </bean>  
59 -  
60 - <bean id="dynamicDataSource" class="com.yoho.core.dal.datasource.DynamicDataSource">  
61 - <property name="defaultTargetDataSource" ref="yohobuylogsMasterDataSource" />  
62 - <property name="targetDataSources">  
63 - <map>  
64 - <entry key="yohobuylogsMasterDataSource" value-ref="yohobuylogsMasterDataSource" />  
65 - </map>  
66 - </property>  
67 - </bean>  
68 -  
69 - <bean id="multipleDataSourceRouter" class="com.yoho.core.dal.datasource.MultiDataSourceRouter">  
70 - <property name="defaultDBCluster" value="yohobuylogsDbCluster" />  
71 - <property name="readOnlyInSlave" value="${jdbc.mysql.readonlyinslave:false}" />  
72 - <property name="dbClusterSet">  
73 - <map>  
74 - <entry key="yohobuylogsDbCluster" value="yohobuylogsMasterDataSource,yohobuylogsMasterDataSource" />  
75 - </map>  
76 - </property>  
77 - <property name="daoDbClusterMap">  
78 - <map>  
79 -  
80 - </map>  
81 - </property>  
82 - </bean>  
83 -  
84 - <bean id="dataSourceMethodInterceptor" class="com.yoho.core.dal.datasource.DataSourceMethodInterceptor">  
85 - </bean>  
86 -  
87 - <aop:config>  
88 - <aop:pointcut id="daoPoint" expression="execution(* com.yoho.*.dal.*.*(..)) " />  
89 - <aop:advisor pointcut-ref="daoPoint" advice-ref="dataSourceMethodInterceptor" />  
90 - </aop:config>  
91 -  
92 -  
93 - <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
94 - <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
95 - <property name="dataSource" ref="dynamicDataSource" />  
96 - <!-- 自动扫描mapping.xml文件 -->  
97 - <property name="mapperLocations" value="classpath*:META-INF/mybatis/*.xml"></property>  
98 - </bean>  
99 - <!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
100 - <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
101 - <property name="basePackage" value="com.yoho.*.dal" />  
102 - <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
103 - </bean>  
104 -  
105 -  
106 -  
107 -</beans>  
1 -  
2 #memcached 1 #memcached
3 cache.servers.memcached.address=192.168.102.162:32768 2 cache.servers.memcached.address=192.168.102.162:32768
4 3
  4 +####暂时不使用,待到订单上线的时候恢复使用#########
5 #MQ 5 #MQ
6 rabbit.mq.host=192.168.102.162 6 rabbit.mq.host=192.168.102.162
7 rabbit.mq.port=32810 7 rabbit.mq.port=32810
  1 +datasources:
  2 + yoho_passport:
  3 + servers:
  4 + - 192.168.50.69:9980
  5 + - 192.168.102.219:3306
  6 + username: yh_test
  7 + password: 9nm0icOwt6bMHjMusIfMLw==
  8 +
  9 +readOnlyInSlave: true
1 -jdbc.mysql.driver=com.mysql.jdbc.Driver  
2 -#定义初始连接数  
3 -jdbc.mysql.initialSize=0  
4 -#定义最大连接数  
5 -jdbc.mysql.maxActive=80  
6 -#定义最大空闲  
7 -jdbc.mysql.maxIdle=60  
8 -#定义最小空闲  
9 -jdbc.mysql.minIdle=10  
10 -#定义最长等待时间  
11 -jdbc.mysql.maxWait=10000  
12 -  
13 -jdbc.mysql.testWhileIdle=true  
14 -jdbc.mysql.timeBetweenEvictionRunsMillis=2000  
15 -jdbc.mysql.validationQuery=select 1  
16 -jdbc.mysql.testOnBorrow=true  
17 -jdbc.mysql.testOnReturn=true  
18 -#读操作是否只在从库  
19 -jdbc.mysql.readonlyinslave=false  
20 -  
21 -#yoho_passport读写数据分离  
22 -jdbc.mysql.yohopassport.master.url=jdbc:mysql://192.168.50.69:9980/yoho_passport  
23 -jdbc.mysql.yohopassport.slave.url=jdbc:mysql://192.168.102.219:3306/yoho_passport  
24 -jdbc.mysql.yohopassport.username=yh_test  
25 -jdbc.mysql.yohopassport.password=yh_test  
1 -  
2 #memcached 1 #memcached
3 cache.servers.memcached.address=${cache.servers.union.address} 2 cache.servers.memcached.address=${cache.servers.union.address}
4 3
  4 +####暂时不使用,待到订单上线的时候恢复使用#########
5 #MQ 5 #MQ
6 rabbit.mq.host=${rabbit.mq.host} 6 rabbit.mq.host=${rabbit.mq.host}
7 rabbit.mq.port=${rabbit.mq.port} 7 rabbit.mq.port=${rabbit.mq.port}
  1 +datasources:
  2 + yoho_passport:
  3 + servers:
  4 + - ${jdbc.mysql.yohopassport.master}
  5 + - ${jdbc.mysql.yohopassport.slave}
  6 + username: ${jdbc.mysql.yohopassport.username}
  7 + password: ${jdbc.mysql.yohopassport.password}
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <display-name>YohoBuy-Resources Service</display-name> 3 <display-name>YohoBuy-Resources Service</display-name>
4 <context-param> 4 <context-param>
5 <param-name>contextConfigLocation</param-name> 5 <param-name>contextConfigLocation</param-name>
6 - <param-value>classpath*:META-INF/spring/spring*.xml</param-value> 6 + <param-value>classpath*:META-INF/spring/spring-mybatis-datasource.xml, classpath*:META-INF/spring/spring*.xml</param-value>
7 </context-param> 7 </context-param>
8 <servlet> 8 <servlet>
9 <servlet-name>dispatcher</servlet-name> 9 <servlet-name>dispatcher</servlet-name>