data-source.xml
6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- DBCP连接池 -->
    <!--<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="defaultAutoCommit" value="false" />
        <property name="filters" value="config" />
        <property name="connectionProperties" value="config.decrypt=true" />
        <property name="maxActive" value="200" />
        <!–<property name="connectionInitSqls" value="set names utf8mb4;"/>–>
    </bean>-->
    <!-- ======================================================================== -->
    <!-- MySQL 主库连接配置 -->
    <!-- ======================================================================== -->
    <bean id="masterDataSource" name="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.mysql.master.driver}" />
        <property name="url" value="${jdbc.mysql.master.url}" />
        <property name="username" value="${jdbc.mysql.master.username}" />
        <property name="password" value="${jdbc.mysql.master.password}" />
        <property name="defaultAutoCommit" value="false" />
        <property name="filters" value="config" />
        <property name="maxActive" value="400" />
        <property name="connectionProperties" value="config.decrypt=true" />
    </bean>
    <!-- ======================================================================== -->
    <!-- MySQL 从库连接配置 -->
    <!-- ======================================================================== -->
    <bean id="slaveDataSource" name="slaveDataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.mysql.slave.driver}" />
        <property name="url" value="${jdbc.mysql.slave.url}" />
        <property name="username" value="${jdbc.mysql.slave.username}" />
        <property name="password" value="${jdbc.mysql.slave.password}" />
        <property name="defaultAutoCommit" value="false" />
        <property name="filters" value="config" />
        <property name="maxActive" value="400" />
        <property name="connectionProperties" value="config.decrypt=true" />
    </bean>
    <!-- ======================================================================== -->
    <!-- 连接配置 -->
    <!-- ======================================================================== -->
    <bean id="dataSource" class="com.xiniunet.framework.data.MultipleDataSource">
        <property name="defaultTargetDataSource" ref="masterDataSource"/>
        <property name="targetDataSources">
            <map>
                <entry key="masterDataSource" value-ref="masterDataSource"/>
                <entry key="slaveDataSource" value-ref="slaveDataSource"/>
            </map>
        </property>
    </bean>
    <!--  TransactionManager定义 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
    <!-- MyBatis配置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描模型对象目录, 省掉Configuration.xml里的手工配置, 改为明确的控制
        <property name="typeAliasesPackage" value="com.xniu.xxx.contract" /> -->
        <!-- 指定Mapper文件位置 -->
        <property name="mapperLocations" value="classpath:/mapper/*/*.xml"/>
        <property name="configLocation"  value="classpath:/mybatis_setting.xml" />
        <property name="configurationProperties">
            <props>
                <prop key="mapUnderscoreToCamelCase">true</prop>
                <prop key="aggressiveLazyLoading">false</prop>
                <prop key="cacheEnabled">true</prop>
                <prop key="useColumnLabel">true</prop>
                <!--<prop key="useGeneratedKeys">true</prop>-->
            </props>
        </property>
    </bean>
    <!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xiniunet.service.*.dal" />
        <property name="annotationClass" value="com.xiniunet.framework.annotation.MyBatisRepository"/>
    </bean>
    <bean id="dbPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="order" value="1" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list>
                <value>classpath*:/jdbc.properties</value>
                <value>classpath*:/setting.properties</value>
            </list>
        </property>
    </bean>
    <bean id="cacheManager" class="com.xiniunet.framework.cache.CacheManagerImpl">
        <constructor-arg value="${aliyun.ocs.host}"/>
        <constructor-arg value="${aliyun.ocs.port}"/>
        <constructor-arg value="${deploy.mode}"/>
        <constructor-arg value="${aliyun.ocs.username}"/>
        <constructor-arg value="${aliyun.ocs.password}"/>
    </bean>
    <bean id="cacheAop" class="com.xiniunet.framework.cache.CacheAop">
    </bean>
    <!-- 服务方法切面配置 -->
    <bean id="serviceMethodAspect" class="com.xiniunet.framework.aop.ServiceMethodAspect"/>
    <aop:config>
        <aop:pointcut id="pointcut" expression="execution(* com.xiniunet.service.railway.svc.*.*(..))"/>
        <aop:aspect id="dataSourceAspect" ref="serviceMethodAspect">
            <aop:before method="doBefore" pointcut-ref="pointcut"/>
            <aop:around method="doAround" pointcut-ref="pointcut"/>
            <aop:after method="doAfter" pointcut-ref="pointcut"/>
        </aop:aspect>
    </aop:config>
</beans>