配置如下:
web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/demoDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
META-INF目录下通过创建context.xml(注意context为小写,linux下吃过亏)。内容如下
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/demoDB" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/mydatabase"
username="root"
password="123456"
maxActive="50"
maxIdle="30"
maxWait="10000" />
</Context>
调用
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
<property name="jndiName">
<value>java:comp/env/jdbc/demoDB</value>
</property>
</bean>