Tomcat5.5 私有JNDI、数据源(链接池)的配置

来源:互联网 发布:怎么查看淘宝卖家等级 编辑:程序博客网 时间:2024/05/16 12:07
可以在两个位置配置JNDI:
1. $CATALINA_HOME/conf/server.xml,在这个文件里的是全局的,对所有应用可见;
2. 应用的context XML文件(META-INF/context.xml),这个是私有的,只对这个应用可见。
大家都知道第一个位置,第二个不熟悉,看看下面的目录结构:

应用目录--
            --WEB-INF/web.xml
            --META_INF/context.xml
            --index.jsp

一个context.xml 文件的例子:
<Context debug="0">
    <Resource name="jdbc/rollerdb" auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/数据库?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8"
        username="用户"
        password="密码"
        maxActive="20"
        maxIdle="3"
        removeAbandoned="true"
        maxWait="3000" />
        <!-- If you want e-mail features, un-comment the section below -->
        <!--
        <Resource name="mail/Session" auth="Container"
        type="javax.mail.Session"
        mail.smtp.host="mailhost.example.com" />
        -->
</Context>

web.xml资源参考部分的代码:
 <!-- Web app resource refs. -->
    <resource-ref>
            <res-ref-name>jdbc/rollerdb</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
    </resource-ref>

原创粉丝点击