想让tomcat下面所有的用户都使用同一个数据连接池.配置如下:
1.在tomcat的server.xml中配置数据连接池如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<
GlobalNamingResources
>
<!-- Editable user database that can also be used by UserDatabaseRealm
to authenticate users -->
<
Resource
name
=
"jdbc/db1"
auth
=
"Container"
type
=
"com.mchange.v2.c3p0.ComboPooledDataSource"
factory
=
"org.apache.naming.factory.BeanFactory"
driverClass
=
"oracle.jdbc.driver.OracleDriver"
jdbcUrl
=
"jdbc:oracle:thin:@XXXXX:1521:orcl"
user
=
"XXXX"
password
=
"XXX"
minPoolSize
=
"10"
maxPoolSize
=
"200"
maxIdleTime
=
"1800"
acquireIncrement
=
"2"
maxStatements
=
"0"
initialPoolSize
=
"20"
idleConnectionTestPeriod
=
"60"
acquireRetryAttempts
=
"30"
acquireRetryDelay
=
"1000"
testConnectionOnCheckin
=
"false"
breakAfterAcquireFailure
=
"false"
testConnectionOnCheckout
=
"false"
/>
<
Resource
auth
=
"Container"
description
=
"User database that can be updated and saved"
factory
=
"org.apache.catalina.users.MemoryUserDatabaseFactory"
name
=
"UserDatabase"
pathname
=
"conf/tomcat-users.xml"
type
=
"org.apache.catalina.UserDatabase"
/>
</
GlobalNamingResources
>
|
在: context.xml里配置:
1
|
<
ResourceLink
global
=
"jdbc/db1"
name
=
"jdbc/db1"
type
=
"javax.sql.DataSource"
/>
|
在Spring配置里将原有的数据源替换为:
1
2
3
4
5
|
<
bean
id
=
"dataSource"
class
=
"org.springframework.jndi.JndiObjectFactoryBean"
>
<
property
name
=
"jndiName"
value
=
"java:comp/env/jdbc/db1"
/>
</
bean
>
|
即可..因为我项目用的数据源是c3p0和oracle数据库.所以要在tomcat的lib里面添加c3p0和oracle jdb的jar包