maven+spring mvc+c3p0连接池如何配置

2025-05-13 16:27:37
推荐回答(2个)
回答1:

pom.xml

4.0.0
com.java
Dao
0.0.1-SNAPSHOT
war



org.apache.maven.plugins
maven-compiler-plugin

1.6
1.6
UTF-8






org.springframework
spring-context
3.2.12.RELEASE


org.springframework
spring-tx
3.2.12.RELEASE


org.springframework
spring-test
3.2.12.RELEASE


org.springframework
spring-orm
3.2.12.RELEASE


junit
junit
4.12


org.springframework
spring-expression
3.2.12.RELEASE


org.springframework
spring-webmvc
3.2.12.RELEASE


org.hibernate
hibernate-core
4.1.12.Final


commons-dbcp
commons-dbcp
1.4


com.oracle
ojdbc5
11.1.0.0


org.aspectj
aspectjrt
1.8.0


org.aspectj
aspectjweaver
1.8.0




C0P3配置:

1
2
3
4
5
6
7
8
9
10

destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost:3306/YTOAttendManageSystem"
p:user="root"
p:password="1234"
p:maxPoolSize="40"
p:minPoolSize="1"
p:initialPoolSize="1"
p:maxIdleTime="20"/>

至于如何将c3p0的具体配置参数放到properties文件里,以C0P3为例:

1
2
3
4
5
6
7
8
9
10

destroy-method="close"
p:driverClass="${driverClass}"
p:jdbcUrl="${jdbcUrl}"
p:user="${user}"
p:password="${password}"
p:maxPoolSize="${maxPoolSize}"
p:minPoolSize="${minPoolSize}"
p:initialPoolSize="${initialPoolSize}"
p:maxIdleTime="${maxIdleTime}"/>

建一个properties文件:

1
2
3

driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/YTOAttendManageSyst

回答2:

pom.xml

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

4.0.0
com.java
Dao
0.0.1-SNAPSHOT
war



org.apache.maven.plugins
maven-compiler-plugin

1.6
1.6
UTF-8






org.springframework
spring-context
3.2.12.RELEASE


org.springframework
spring-tx
3.2.12.RELEASE


org.springframework
spring-test
3.2.12.RELEASE


org.springframework
spring-orm
3.2.12.RELEASE


junit
junit
4.12


org.springframework
spring-expression
3.2.12.RELEASE


org.springframework
spring-webmvc
3.2.12.RELEASE


org.hibernate
hibernate-core
4.1.12.Final


commons-dbcp
commons-dbcp
1.4


com.oracle
ojdbc5
11.1.0.0


org.aspectj
aspectjrt
1.8.0


org.aspectj
aspectjweaver
1.8.0