tomcat conf下context.xml:
<Context path="/WebRoot" reloadable="true" docBase="E:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\MonthlyReport" >
<Resource name="jdbc/monthlyReport"
auth="Container"
type="javax.sql.DataSource"
maxActive="50"
maxIdle="30"
maxWait="10000"
logAbandoned="true"
username="root"
password="123456"
testOnBorrow = "true"
testOnReturn = "true"
testWhileIdle = "true"
validationQuery = " select 1 "
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/monthlyreport"/>
</Context>
Tomcat lib目录下要加入3.0以上的数据库驱动jar包
Web.xml
<resource-ref>
<description>MonthlyReport</description>
<res-ref-name>jdbc/monthlyReport</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Spring配置
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/monthlyReport</value>
</property>
</bean>