#
18516761980
2022-07-26 78423189c7165a5e4bffbfadd5dd181ad9114a2f
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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.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
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                       http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
    <!--自动扫描注解注入 -->
    <context:component-scan base-package="com.slcf.*"></context:component-scan>
    
    <!-- 配置整合mybatis过程 -->
    <!-- 1.配置数据库相关参数properties的属性:${url} -->
    <context:property-placeholder location="classpath:jdbc.properties" />
 
    <!-- 2.数据库连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!-- 配置连接池属性 -->
        <property name="driverClass" value="${jdbc.driver}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
 
        <!-- c3p0连接池的私有属性 -->
        <property name="maxPoolSize" value="30" />
        <property name="minPoolSize" value="10" />
        <!-- 关闭连接后不自动commit -->
        <property name="autoCommitOnClose" value="false" />
        <!-- 获取连接超时时间 -->
        <property name="checkoutTimeout" value="10000" />
        <!-- 当获取连接失败重试次数 -->
        <property name="acquireRetryAttempts" value="2" />
    </bean>
 
    <!-- 3.配置SqlSessionFactory对象 -->
    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 扫描sql配置文件:自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:mapper/*Mapper.xml"></property> <!--只加载映射文件*.xml得区分 -->
    </bean>
 
    <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
    <!-- DAO接口所在包名,Spring会自动查找其下的类,与数据库交互的那层 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.slcf.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
 
    <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
 
    <!-- 配置Spring声明式事务处理 使用基于xml文件的声明式事务处理 -->
    <!-- 定义事务通知 -->
     <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!-- 事务的传播属性 -->
         <tx:attributes>
            <!-- propagation="REQUIRED"事务传播行为(必须)默认值 有就加入,没有就添加 isolation="DEFAULT"隔离级别(可选)数据库增删改查单独不受影响 -->
            <tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT" read-only="false" />
            <tx:method name="del*" />
            <tx:method name="query*" />
            <tx:method name="is*" />
            <tx:method name="up*" />
            <tx:method name="move*" />
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="modify*" propagation="REQUIRED" />
            <tx:method name="edit*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
 
            <tx:method name="get*" propagation="SUPPORTS" />
            <tx:method name="find*" propagation="SUPPORTS" />
            <tx:method name="load*" propagation="SUPPORTS" />
            <tx:method name="search*" propagation="SUPPORTS" />
 
            <!-- <tx:method name="*" propagation="SUPPORTS" /> -->
        </tx:attributes> 
    </tx:advice>
 
    <!-- 定义事务切面配置 -->
    <aop:config>
        <!--切面操作的是service -->
        <aop:pointcut expression="execution(* com.slcf.service.*.*.*(..))"
            id="pointCut" /><!--在哪个类进行事务处理 --><!-- 哪个包下的哪个类的哪个方法 -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut" />
    </aop:config>
    
    <!-- 引入activiti工作流 -->
    <import resource="classpath:activiti-context.xml"/>
 
    <bean id="waitPakInService" class="com.slcf.service.impl.WaitPakInServiceImpl"></bean>
    <bean id="waitPakOutService" class="com.slcf.service.impl.WaitPakOutServiceImpl"></bean>
    <bean id="updateThread" class="com.slcf.filter.UpdateThread">
        <property name="waitPakInService" ref="waitPakInService"></property>
        <property name="waitPakOutService" ref="waitPakOutService"></property>
    </bean>
    
</beans>