获取JNDI数据源

1 在容器中配置数据源

Tomcat

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="jdbc/JavaWeb" auth="Container"
              type="javax.sql.DataSource"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/JavaWeb"
              username="root"
              password="123456"
              maxActive="50"
              maxIdle="30"
              maxWait="10000" />
</Context>

2 Spring中获取数据源

<jee:jndi-lookup id="dataSource_MySQL_JavaWeb" jndi-name="java:comp/env/jdbc/JavaWeb"/>

3 web.xml设置数据源

    <!--数据源-->
    <resource-ref>
        <description>MySQL DB Pool</description>
        <res-ref-name>jdbc/JavaWeb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
原文地址:https://www.cnblogs.com/sherrykid/p/4623254.html