93249314 陈志杭(后端)

添加新系统数据源与mybatis配置

1 个父辈 7e1707c7
......@@ -4,6 +4,19 @@ jdbc.driverClassName=com.mysql.jdbc.Driver
#数据库url
jdbc.imtegralurl=jdbc:mysql://10.170.4.106/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8
mall.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop
mall.write.username=sibu_wesale
mall.write.password=sibu123..
mall.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop
mall.read.username=sibu_wesale
mall.read.password=sibu123..
mall.analysis.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop
mall.analysis.write.username=sibu_wesale
mall.analysis.write.password=sibu123..
mall.analysis.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop
mall.analysis.read.username=sibu_wesale
mall.analysis.read.password=sibu123..
#数据库用户名
jdbc.imtegralusername=sibu_integralmall
......
......@@ -7,6 +7,19 @@ jdbc.url=jdbc:mysql://120.76.137.184/sibu_wesale_base?useUnicode=true&characterE
jdbc.imtegralurl=jdbc:mysql://120.76.137.184/sibu_integralmall_base?useUnicode=true&characterEncoding=utf8
sqlserverjdbc.url=jdbc\:jtds\:sqlserver\://120.25.75.53\:1433;databaseName\=sibu_wesale_base_read_03
mall.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop
mall.write.username=sibu_wesale
mall.write.password=sibu123..
mall.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop
mall.read.username=sibu_wesale
mall.read.password=sibu123..
mall.analysis.write.url=jdbc:mysql://39.108.19.165:3306/ejavashop
mall.analysis.write.username=sibu_wesale
mall.analysis.write.password=sibu123..
mall.analysis.read.url=jdbc:mysql://120.77.6.187:3306/ejavashop
mall.analysis.read.username=sibu_wesale
mall.analysis.read.password=sibu123..
#数据库用户名
jdbc.username=root
sqlserverjdbc.username=sa
......
package com.sibu.orderHelper.mall.member.read;
import com.sibu.orderHelper.integral.reponse.MemberAddressResponse;
import com.sibu.orderHelper.integral.request.MemberAddressAddRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface MemberReadDao {
Integer count();
}
package com.sibu.orderHelper.mall.member.write;
public interface MemberWriteDao {
Integer count();
}
......@@ -10,6 +10,8 @@ import com.sibu.orderHelper.common.util.SpringValuesUtil;
import com.sibu.orderHelper.integral.service.IIMDoingOrderService;
import com.sibu.orderHelper.integral.vo.PayType;
import com.sibu.orderHelper.integralMall.controller.BaseController;
import com.sibu.orderHelper.mall.member.read.MemberReadDao;
import com.sibu.orderHelper.mall.member.write.MemberWriteDao;
import org.apache.commons.lang3.time.DateUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
......@@ -18,11 +20,9 @@ import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.ValidationException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
......@@ -47,6 +47,21 @@ import java.util.Map;
public class IMOrderTestController extends BaseController {
@Autowired
private IIMDoingOrderService iimDoingOrderService;
@Resource
private MemberReadDao memberReadDao;
@Resource
private MemberWriteDao memberWriteDao;
/**
*
*
* @return
*/
@RequestMapping(value = "/test/mall/read-write/datasource", method = RequestMethod.GET)
public BaseResponse testReadAndWriteDb() {
String r = String.format("%s-%s", memberReadDao.count(), memberWriteDao.count());
return ResponseRender.renderData(r);
}
/**
* 验证测试环境
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sibu.orderHelper.mall.member.read.MemberReadDao">
<select id="count" resultType="java.lang.Integer">
select count(*) from member
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sibu.orderHelper.mall.member.write.MemberWriteDao">
<select id="count" resultType="java.lang.Integer">
select count(*) from member
</select>
</mapper>
\ No newline at end of file
......@@ -37,6 +37,110 @@
<!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" mode="proxy"/>
<!-- begin 新系统mall -->
<bean id="mallReadDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${mall.read.url}?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
<property name="username" value="${mall.read.username}" />
<property name="password" value="${mall.read.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="1"/>
<property name="minIdle" value="1"/>
<property name="maxActive" value="200"/>
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000"/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="validationQuery" value="SELECT 'x'"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat"/>
</bean>
<bean id="mallReadSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath:mall-mapper/**/read/**/*.xml" />
<!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />-->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<property name="dataSource" ref="mallReadDataSource"/>
</bean>
<bean name="mallReadMapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sibu.orderHelper.mall.*.read" />
<property name="sqlSessionFactoryBeanName" value="mallReadSqlSessionFactory" />
</bean>
<bean id="mallWriteDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="url" value="${mall.write.url}?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
<property name="username" value="${mall.write.username}" />
<property name="password" value="${mall.write.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="1"/>
<property name="minIdle" value="1"/>
<property name="maxActive" value="200"/>
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="60000"/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="validationQuery" value="SELECT 'x'"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize" value="20"/>
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="stat"/>
</bean>
<bean id="mallWriteSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath:mall-mapper/**/write/**/*.xml" />
<!--<property name="typeAliasesPackage" value="com.ejavashop.entity" />-->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<property name="dataSource" ref="mallWriteDataSource" />
</bean>
<bean name="shopMapperScannerWrite" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.sibu.orderHelper.mall.*.write" />
<property name="sqlSessionFactoryBeanName" value="mallWriteSqlSessionFactory" />
</bean>
<bean id="transactionManagerForMall" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="mallWriteDataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManagerForMall"/>
<!-- end 新系统mall -->
<!-- 配置事务的传播特性 -->
<!--<tx:advice id="txAdvice" transaction-manager="transactionManager">-->
<!--<tx:attributes>-->
......