在tomcat中用jndi配置数据源启动java web程序

1.在web.xml中添加:

<resource-ref>
    <res-ref-name>jdbc/MTSDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
 </resource-ref>

 

2.在tomcat的context.xml中配置数据源:

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
  factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
  maxActive="20" maxIdel="10" maxWait="1000" name="jdbc/MTSDB" password="passw0rd"
  type="javax.sql.DataSource"
  url="jdbc:mysql://10.19.220.36:3306/mobdb?autoReconnect=true&amp;characterEncoding=utf8&amp;useUnicode=true&amp;generateSimpleParameterMetadata=true"
  username="mobuser" />

3.在property配置文件中添加变量

mcsJNDI=java:comp/env/jdbc/MTSDB

posted @ 2016-10-25 09:34  ppjj  阅读(841)  评论(0编辑  收藏  举报