cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
125
126
127
128
129
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            http://www.springframework.org/schema/task
            http://www.springframework.org/schema/task/spring-task.xsd">
 
    <!-- 开启定时任务注解 -->
    <task:annotation-driven/>
     <!-- 开启注解 -->
    <context:annotation-config/>
    <context:component-scan base-package="cn.ksource">
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
 
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:app.properties</value>
            </list>
        </property>
    </bean>
 
 
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
           <property name="driverClass" value="${jdbc.driverClassName}" />
           <property name="jdbcUrl" value="${jdbc.url}" />
           <property name="username" value="${jdbc.username}"/>
           <property name="password" value="${jdbc.password}"/>
           <property name="maxConnectionsPerPartition" value="10"/>
           <property name="minConnectionsPerPartition" value="2"/>
           <property name="partitionCount" value="3"/>
           <property name="acquireIncrement" value="2"/>
           <property name="statementsCacheSize" value="100"/>
           <property name="releaseHelperThreads" value="3"/>
    </bean>
    
 
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">   
        <property name="dataSource" ref="dataSource"></property>   
    </bean>   
    
    <!--  配置事务传播特性 <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" read-only="false"/> -->
    <tx:advice id="TransactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
          <tx:method name="do*" propagation="REQUIRED"/>
          <tx:method name="set*" propagation="REQUIRED"/>
          <tx:method name="modify*" propagation="REQUIRED"/>
          <tx:method name="update*" propagation="REQUIRED"/>
          <tx:method name="remove*" propagation="REQUIRED"/>
          <tx:method name="delete*" propagation="REQUIRED"/>
          <tx:method name="del*" propagation="REQUIRED"/>
          <tx:method name="edit*" propagation="REQUIRED"/>
          <tx:method name="exec*" propagation="REQUIRED"/>
          <tx:method name="save*" propagation="REQUIRED"/>
          <tx:method name="add*" propagation="REQUIRED"/>
          <tx:method name="insert*" propagation="REQUIRED"/>
          <tx:method name="*Submit" propagation="REQUIRED"/>
          <tx:method name="*Delete" propagation="REQUIRED"/>
          <tx:method name="*Update" propagation="REQUIRED"/>
          <tx:method name="send*" propagation="REQUIRED"/>
          <tx:method name="*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    
    <!--  配置参与事务的类 -->
    <aop:config>
    <aop:pointcut id="allTransactionServiceMethod" expression="execution(* cn.ksource.web.facade..*.*(..))"/>
    <aop:advisor pointcut-ref="allTransactionServiceMethod" advice-ref="TransactionAdvice" />
    </aop:config>
    
    
    <!-- 如果是使用freemarker最为视图模板需要再spring的配置文件applicationContext.xml中加入以下配置 -->
    <!--  
    <bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    -->
    <bean id="freemarkerConfig"
        class="cn.ksource.core.web.MyFreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/" />
        <property name="freemarkerSettings">
            <props>
                <prop key="template_update_delay">0</prop>
                <prop key="default_encoding">UTF-8</prop>
                <prop key="number_format">0.##########</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                <prop key="classic_compatible">true</prop>
                <prop key="template_exception_handler">ignore</prop>
            </props>
        </property>
    </bean>
    
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>
 
    <bean id="springBeanUtil" class="cn.ksource.core.spring.SpringBeanUtil"></bean>
 
    <bean id="paraJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
        <constructor-arg ref="jdbcTemplate" />
    </bean>
    
    <bean id="baseDao" class="cn.ksource.core.dao.BaseDao">
        <property name="jdbcTemplate" ref="jdbcTemplate" />
        <property name="paraJdbcTemplate" ref="paraJdbcTemplate" />
    </bean>
    
    <bean id="taskExecutor"
        class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="corePoolSize" value="10" />
        <property name="keepAliveSeconds" value="200" />
        <property name="maxPoolSize" value="10" />
        <property name="queueCapacity" value="60" />
    </bean>
</beans>