添加新系统数据源与mybatis配置
正在显示
8 个修改的文件
包含
186 行增加
和
4 行删除
| ... | @@ -4,6 +4,19 @@ jdbc.driverClassName=com.mysql.jdbc.Driver | ... | @@ -4,6 +4,19 @@ jdbc.driverClassName=com.mysql.jdbc.Driver |
| 4 | #数据库url | 4 | #数据库url |
| 5 | jdbc.imtegralurl=jdbc:mysql://10.170.4.106/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8 | 5 | jdbc.imtegralurl=jdbc:mysql://10.170.4.106/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8 |
| 6 | 6 | ||
| 7 | mall.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop | ||
| 8 | mall.write.username=sibu_wesale | ||
| 9 | mall.write.password=sibu123.. | ||
| 10 | mall.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop | ||
| 11 | mall.read.username=sibu_wesale | ||
| 12 | mall.read.password=sibu123.. | ||
| 13 | mall.analysis.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop | ||
| 14 | mall.analysis.write.username=sibu_wesale | ||
| 15 | mall.analysis.write.password=sibu123.. | ||
| 16 | mall.analysis.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop | ||
| 17 | mall.analysis.read.username=sibu_wesale | ||
| 18 | mall.analysis.read.password=sibu123.. | ||
| 19 | |||
| 7 | #数据库用户名 | 20 | #数据库用户名 |
| 8 | jdbc.imtegralusername=sibu_integralmall | 21 | jdbc.imtegralusername=sibu_integralmall |
| 9 | 22 | ... | ... |
| ... | @@ -7,6 +7,19 @@ jdbc.url=jdbc:mysql://120.76.137.184/sibu_wesale_base?useUnicode=true&characterE | ... | @@ -7,6 +7,19 @@ jdbc.url=jdbc:mysql://120.76.137.184/sibu_wesale_base?useUnicode=true&characterE |
| 7 | jdbc.imtegralurl=jdbc:mysql://120.76.137.184/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8 | 7 | jdbc.imtegralurl=jdbc:mysql://120.76.137.184/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8 |
| 8 | sqlserverjdbc.url=jdbc\:jtds\:sqlserver\://120.25.75.53\:1433;databaseName\=sibu_wesale_base_read_03 | 8 | sqlserverjdbc.url=jdbc\:jtds\:sqlserver\://120.25.75.53\:1433;databaseName\=sibu_wesale_base_read_03 |
| 9 | 9 | ||
| 10 | mall.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop | ||
| 11 | mall.write.username=sibu_wesale | ||
| 12 | mall.write.password=sibu123.. | ||
| 13 | mall.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop | ||
| 14 | mall.read.username=sibu_wesale | ||
| 15 | mall.read.password=sibu123.. | ||
| 16 | mall.analysis.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop | ||
| 17 | mall.analysis.write.username=sibu_wesale | ||
| 18 | mall.analysis.write.password=sibu123.. | ||
| 19 | mall.analysis.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop | ||
| 20 | mall.analysis.read.username=sibu_wesale | ||
| 21 | mall.analysis.read.password=sibu123.. | ||
| 22 | |||
| 10 | #数据库用户名 | 23 | #数据库用户名 |
| 11 | jdbc.username=root | 24 | jdbc.username=root |
| 12 | sqlserverjdbc.username=sa | 25 | sqlserverjdbc.username=sa | ... | ... |
com.sibu.orderHelper.dao/src/main/java/com/sibu/orderHelper/mall/member/read/MemberReadDao.java
0 → 100644
| 1 | package com.sibu.orderHelper.mall.member.read; | ||
| 2 | |||
| 3 | import com.sibu.orderHelper.integral.reponse.MemberAddressResponse; | ||
| 4 | import com.sibu.orderHelper.integral.request.MemberAddressAddRequest; | ||
| 5 | import org.apache.ibatis.annotations.Param; | ||
| 6 | |||
| 7 | import java.util.List; | ||
| 8 | import java.util.Map; | ||
| 9 | |||
| 10 | public interface MemberReadDao { | ||
| 11 | Integer count(); | ||
| 12 | } |
| ... | @@ -10,6 +10,8 @@ import com.sibu.orderHelper.common.util.SpringValuesUtil; | ... | @@ -10,6 +10,8 @@ import com.sibu.orderHelper.common.util.SpringValuesUtil; |
| 10 | import com.sibu.orderHelper.integral.service.IIMDoingOrderService; | 10 | import com.sibu.orderHelper.integral.service.IIMDoingOrderService; |
| 11 | import com.sibu.orderHelper.integral.vo.PayType; | 11 | import com.sibu.orderHelper.integral.vo.PayType; |
| 12 | import com.sibu.orderHelper.integralMall.controller.BaseController; | 12 | import com.sibu.orderHelper.integralMall.controller.BaseController; |
| 13 | import com.sibu.orderHelper.mall.member.read.MemberReadDao; | ||
| 14 | import com.sibu.orderHelper.mall.member.write.MemberWriteDao; | ||
| 13 | import org.apache.commons.lang3.time.DateUtils; | 15 | import org.apache.commons.lang3.time.DateUtils; |
| 14 | import org.aspectj.lang.ProceedingJoinPoint; | 16 | import org.aspectj.lang.ProceedingJoinPoint; |
| 15 | import org.aspectj.lang.annotation.Around; | 17 | import org.aspectj.lang.annotation.Around; |
| ... | @@ -18,11 +20,9 @@ import org.aspectj.lang.annotation.Pointcut; | ... | @@ -18,11 +20,9 @@ import org.aspectj.lang.annotation.Pointcut; |
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.http.MediaType; | 21 | import org.springframework.http.MediaType; |
| 20 | import org.springframework.stereotype.Controller; | 22 | import org.springframework.stereotype.Controller; |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | 23 | import org.springframework.web.bind.annotation.*; |
| 22 | import org.springframework.web.bind.annotation.RequestMethod; | ||
| 23 | import org.springframework.web.bind.annotation.ResponseBody; | ||
| 24 | import org.springframework.web.bind.annotation.RestController; | ||
| 25 | 24 | ||
| 25 | import javax.annotation.Resource; | ||
| 26 | import javax.validation.ValidationException; | 26 | import javax.validation.ValidationException; |
| 27 | import java.io.BufferedReader; | 27 | import java.io.BufferedReader; |
| 28 | import java.io.InputStreamReader; | 28 | import java.io.InputStreamReader; |
| ... | @@ -47,6 +47,21 @@ import java.util.Map; | ... | @@ -47,6 +47,21 @@ import java.util.Map; |
| 47 | public class IMOrderTestController extends BaseController { | 47 | public class IMOrderTestController extends BaseController { |
| 48 | @Autowired | 48 | @Autowired |
| 49 | private IIMDoingOrderService iimDoingOrderService; | 49 | private IIMDoingOrderService iimDoingOrderService; |
| 50 | @Resource | ||
| 51 | private MemberReadDao memberReadDao; | ||
| 52 | @Resource | ||
| 53 | private MemberWriteDao memberWriteDao; | ||
| 54 | |||
| 55 | /** | ||
| 56 | * | ||
| 57 | * | ||
| 58 | * @return | ||
| 59 | */ | ||
| 60 | @RequestMapping(value = "/test/mall/read-write/datasource", method = RequestMethod.GET) | ||
| 61 | public BaseResponse testReadAndWriteDb() { | ||
| 62 | String r = String.format("%s-%s", memberReadDao.count(), memberWriteDao.count()); | ||
| 63 | return ResponseRender.renderData(r); | ||
| 64 | } | ||
| 50 | 65 | ||
| 51 | /** | 66 | /** |
| 52 | * 验证测试环境 | 67 | * 验证测试环境 | ... | ... |
com.sibu.orderHelper.integralMall/src/main/resources/mall-mapper/member/read/MemberReadMapper.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | <!DOCTYPE mapper | ||
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | <mapper namespace="com.sibu.orderHelper.mall.member.read.MemberReadDao"> | ||
| 6 | |||
| 7 | <select id="count" resultType="java.lang.Integer"> | ||
| 8 | select count(*) from member | ||
| 9 | </select> | ||
| 10 | </mapper> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
com.sibu.orderHelper.integralMall/src/main/resources/mall-mapper/member/write/MemberWriteMapper.xml
0 → 100644
| 1 | <?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | <!DOCTYPE mapper | ||
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | <mapper namespace="com.sibu.orderHelper.mall.member.write.MemberWriteDao"> | ||
| 6 | |||
| 7 | <select id="count" resultType="java.lang.Integer"> | ||
| 8 | select count(*) from member | ||
| 9 | </select> | ||
| 10 | </mapper> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -37,6 +37,110 @@ | ... | @@ -37,6 +37,110 @@ |
| 37 | <!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 --> | 37 | <!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 --> |
| 38 | <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" mode="proxy"/> | 38 | <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" mode="proxy"/> |
| 39 | 39 | ||
| 40 | |||
| 41 | |||
| 42 | <!-- begin 新系统mall --> | ||
| 43 | <bean id="mallReadDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> | ||
| 44 | <!-- 基本属性 url、user、password --> | ||
| 45 | <property name="url" value="${mall.read.url}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true" /> | ||
| 46 | <property name="username" value="${mall.read.username}" /> | ||
| 47 | <property name="password" value="${mall.read.password}" /> | ||
| 48 | |||
| 49 | <!-- 配置初始化大小、最小、最大 --> | ||
| 50 | <property name="initialSize" value="1"/> | ||
| 51 | <property name="minIdle" value="1"/> | ||
| 52 | <property name="maxActive" value="200"/> | ||
| 53 | |||
| 54 | <!-- 配置获取连接等待超时的时间 --> | ||
| 55 | <property name="maxWait" value="60000"/> | ||
| 56 | |||
| 57 | <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> | ||
| 58 | <property name="timeBetweenEvictionRunsMillis" value="60000"/> | ||
| 59 | |||
| 60 | <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> | ||
| 61 | <property name="minEvictableIdleTimeMillis" value="300000"/> | ||
| 62 | |||
| 63 | <property name="validationQuery" value="SELECT 'x'"/> | ||
| 64 | <property name="testWhileIdle" value="true"/> | ||
| 65 | <property name="testOnBorrow" value="false"/> | ||
| 66 | <property name="testOnReturn" value="false"/> | ||
| 67 | |||
| 68 | <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> | ||
| 69 | <property name="poolPreparedStatements" value="true"/> | ||
| 70 | <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> | ||
| 71 | |||
| 72 | <!-- 配置监控统计拦截的filters --> | ||
| 73 | <property name="filters" value="stat"/> | ||
| 74 | </bean> | ||
| 75 | |||
| 76 | <bean id="mallReadSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> | ||
| 77 | <property name="mapperLocations" value="classpath:mall-mapper/**/read/**/*.xml" /> | ||
| 78 | <!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />--> | ||
| 79 | <property name="configLocation" value="classpath:mybatis-config.xml"></property> | ||
| 80 | <property name="dataSource" ref="mallReadDataSource"/> | ||
| 81 | </bean> | ||
| 82 | <bean name="mallReadMapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> | ||
| 83 | <property name="basePackage" value="com.sibu.orderHelper.mall.*.read" /> | ||
| 84 | <property name="sqlSessionFactoryBeanName" value="mallReadSqlSessionFactory" /> | ||
| 85 | </bean> | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | <bean id="mallWriteDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> | ||
| 90 | <!-- 基本属性 url、user、password --> | ||
| 91 | <property name="url" value="${mall.write.url}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true" /> | ||
| 92 | <property name="username" value="${mall.write.username}" /> | ||
| 93 | <property name="password" value="${mall.write.password}" /> | ||
| 94 | |||
| 95 | <!-- 配置初始化大小、最小、最大 --> | ||
| 96 | <property name="initialSize" value="1"/> | ||
| 97 | <property name="minIdle" value="1"/> | ||
| 98 | <property name="maxActive" value="200"/> | ||
| 99 | |||
| 100 | <!-- 配置获取连接等待超时的时间 --> | ||
| 101 | <property name="maxWait" value="60000"/> | ||
| 102 | |||
| 103 | <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> | ||
| 104 | <property name="timeBetweenEvictionRunsMillis" value="60000"/> | ||
| 105 | |||
| 106 | <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> | ||
| 107 | <property name="minEvictableIdleTimeMillis" value="300000"/> | ||
| 108 | |||
| 109 | <property name="validationQuery" value="SELECT 'x'"/> | ||
| 110 | <property name="testWhileIdle" value="true"/> | ||
| 111 | <property name="testOnBorrow" value="false"/> | ||
| 112 | <property name="testOnReturn" value="false"/> | ||
| 113 | |||
| 114 | <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> | ||
| 115 | <property name="poolPreparedStatements" value="true"/> | ||
| 116 | <property name="maxPoolPreparedStatementPerConnectionSize" value="20"/> | ||
| 117 | |||
| 118 | <!-- 配置监控统计拦截的filters --> | ||
| 119 | <property name="filters" value="stat"/> | ||
| 120 | </bean> | ||
| 121 | |||
| 122 | <bean id="mallWriteSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> | ||
| 123 | <property name="mapperLocations" value="classpath:mall-mapper/**/write/**/*.xml" /> | ||
| 124 | <!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />--> | ||
| 125 | <property name="configLocation" value="classpath:mybatis-config.xml"></property> | ||
| 126 | <property name="dataSource" ref="mallWriteDataSource" /> | ||
| 127 | </bean> | ||
| 128 | |||
| 129 | <bean name="shopMapperScannerWrite" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> | ||
| 130 | <property name="basePackage" value="com.sibu.orderHelper.mall.*.write" /> | ||
| 131 | <property name="sqlSessionFactoryBeanName" value="mallWriteSqlSessionFactory" /> | ||
| 132 | </bean> | ||
| 133 | |||
| 134 | <bean id="transactionManagerForMall" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> | ||
| 135 | <property name="dataSource" ref="mallWriteDataSource"/> | ||
| 136 | </bean> | ||
| 137 | |||
| 138 | <tx:annotation-driven transaction-manager="transactionManagerForMall"/> | ||
| 139 | |||
| 140 | <!-- end 新系统mall --> | ||
| 141 | |||
| 142 | |||
| 143 | |||
| 40 | <!-- 配置事务的传播特性 --> | 144 | <!-- 配置事务的传播特性 --> |
| 41 | <!--<tx:advice id="txAdvice" transaction-manager="transactionManager">--> | 145 | <!--<tx:advice id="txAdvice" transaction-manager="transactionManager">--> |
| 42 | <!--<tx:attributes>--> | 146 | <!--<tx:attributes>--> | ... | ... |
-
请 注册 或 登录 后发表评论