<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/myds"/>
跟Tomcat和Spring连接池使用指南
1. 在META-INF创建
context.xml.内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true" crossContext="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/ebus" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/rayln"
username="rayln" password="xxxxxx" maxActive="200" maxIdle="100"
maxWait="-1" />
</Context>
或者在Tomcat的
server.xml中修改
原来的
<Context path="" docBase="" reloadable="true" />
修改为:
<Context path="" docBase="" reloadable="true">
<Resource name="jdbc/数据源名称" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/数据库名?characterEncoding=GBK&useUnicode=true"
username="用户" password="密码" maxActive="100" maxIdle="10"
maxWait="-1"/>
</Context>
2. 修改web.xml
<resource-ref>
<description>SQLServer Datasource</description>
<res-ref-name>jdbc/ebus</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. Spring的applicationContext.xml中加入
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/ebus</value>
</property>
</bean>
dataSource就是连接!!