jndi方式配置c3p0
程序员文章站
2022-05-24 11:59:54
...
环境:tomcat6.0、eclipse-jee-galileo-SR2-win32
添加mysql-connector-java-5.1.5-bin.jar,c3p0-0.9.1.jar到tomcat的lib,此时应该保证项目的lib下没有这2个jar包
添加context.xml到项目的META-INF
context.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true" crossContext="true">
<ResourceLink name="jdbc/mysql" global="jdbc/dbcp/mysql/test" type="java.sql.DataSource">
</ResourceLink>
</Context>
或者在tomcat6.0\conf \context.xml文件中加入:
<Context>
<ResourceLink name="jdbc/mysql" global="jdbc/dbcp/mysql/test" type="java.sql.DataSource"></ResourceLink>
</Context>
server.xml部分配置(eclipse中项目列表会有一个Servers项目,在这里配置):
<GlobalNamingResources>
<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"/>
<Resource acquireIncrement="5"
auth="Container"
driverClass="com.mysql.jdbc.Driver"
factory="org.apache.naming.factory.BeanFactory"
initialPoolSize="10"
jdbcUrl="jdbc:mysql://localhost:3306/APPMALL"
maxIdleTime="120"
maxPoolSize="200"
maxStatements="1000"
minPoolSize="5"
name="jdbc/dbcp/mysql/test"
password="root"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
user="root"/>
</GlobalNamingResources>
spring.xml配置:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/mysql" />
</bean>