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
|
<? xml version = "1.0" encoding = "UTF-8" ?> xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 定义数据源Bean,使用C3P0数据源实现 --> < bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method = "close" > <!-- 指定连接数据库的驱动 --> < property name = "driverClass" value = "com.mysql.jdbc.Driver" /> <!-- 指定连接数据库的URL --> <!-- 指定连接数据库的用户名 --> < property name = "user" value = "root" /> <!-- 指定连接数据库的密码 --> < property name = "password" value = "root" /> <!-- 指定连接数据库连接池的最大连接数 --> < property name = "maxPoolSize" value = "40" /> <!-- 指定连接数据库连接池的最小连接数 --> < property name = "minPoolSize" value = "5" /> <!-- 指定连接数据库连接池的初始化连接数 --> < property name = "initialPoolSize" value = "1" /> <!-- 指定连接数据库连接池的连接的最大空闲时间 --> < property name = "maxIdleTime" value = "20" /> </ bean > <!-- 配置SessionFactory --> < bean id = "sf" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" > < property name = "dataSource" ref = "dataSource" ></ property > < property name = "configLocation" value = "classpath:hibernate.cfg.xml" ></ property > </ bean > <!-- 配置事务管理器--> < bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" > < property name = "dataSource" ref = "dataSource" /> < property name = "sessionFactory" > < ref bean = "sf" /> </ property > </ bean > <!-- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> --> < tx:advice id = "txAdvice" transaction-manager = "transactionManager" > < tx:attributes > <!-- 所有以'get'开头的方法是read-only的 --> < tx:method name = "get*" read-only = "true" /> < tx:method name = "find*" read-only = "true" /> <!-- 其他方法使用默认的事务设置 --> < tx:method name = "*" /> </ tx:attributes > </ tx:advice > < aop:config > < aop:pointcut id = "allMethod" expression = "execution(* cn.hbcf.edu.service.impl.*Impl.*(..))" /> < aop:advisor pointcut-ref = "allMethod" advice-ref = "txAdvice" /> </ aop:config > </ beans > |