tomcat JNDI configuration

tomcat JNDI configuration:
第一种:全局配置。
1)在tomcat的conf文件夹下的context.xml中:
	<Resource name="jndi/mysql" 
				auth="Container" 
				type="javax.sql.DataSource" 
				driverClassName="com.mysql.jdbc.Driver" 
				url="jdbc:mysql://localhost:3306/appdb" 
				username="root" 
				password="root" 
				maxActive="20" 
				maxIdle="10" 
				maxWait="10000"/>	

2)在项目的web.xml中加入资源引用:
<resource-ref>
  <description>JNDI DataSource</description>
  <res-ref-name>jndi/mysql</res-ref-name>
  <res-ref-type>javax.sql.DataSource</res-ref-type>
  <res-auth>Container</res-auth>
</resource-ref>

第二种:局部配置(不推荐)。
1)在tomcat的server.xml的<host>标签内,添加:
	
<Context path="/jee_jndi" docBase="/jee_jndi">
		   <Resource
			 name="jndi/mysql"
			 type="javax.sql.DataSource"
			 driverClassName="com.mysql.jdbc.Driver"
			 maxIdle="2"
			 maxWait="5000"
			 username="root"
			 password="123456"
			 url="jdbc:mysql://localhost:3306/appdb"
			 maxActive="4"/>
		</Context>

第三种:局部配置。
1)在项目的META-INFO下面新建context.xml。加入:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
	<Resource name="jndi/mysql" 
				auth="Container" 
				type="javax.sql.DataSource" 
				driverClassName="com.mysql.jdbc.Driver" 
				url="jdbc:mysql://localhost:3306/devdb" 
				username="root" 
				password="root" 
				maxActive="20" 
				maxIdle="10" 
				maxWait="10000"/>	
</Context>

总结:
1.在项目的web.xml中添加的资源引用可有可无。
2.推荐第一种全局配置。

猜你喜欢

转载自wangbing9577.iteye.com/blog/2156004