1. 配置tomcat文件中conf/context.xml,在<context></context>中添加以下代码
配置tomcat文件中conf/server.xml,在<GlobalNamingResources><</GlobalNamingResources>中添加以下代码
<Resource name="jdbc/数据库名称"
auth="Container"
type="javax.sql.DataSource"
maxTotal="100" maxIdle="30"
maxWaitMillis="10000"
username="root"
password="******"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/数据库名称"/> //&字符需要&转义使用
2. 配置web项目中web-INFO文件夹中的web.xml文件
<resource-ref>
<description>mysql</description>
<res-ref-name>jdbc/数据库名</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. Spring核心配置文件中
<!-- 配置jndi的数据源 -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/数据库名</value>
</property>
</bean>