润乾在jetty应用服务器下的JNDI配置一



一、 此处绑定的数据源是以 DBCP 为实现。首先必须将数据库驱动(这里用了MYSQL数据库)和DBCP所需要的 Jar 包复制到 Jetty 根目录的 lib 目录下。DBCP主要需要以下3个文件:
Commons-dbcp.jar
Commons-pool.jar
Commons-collections.jar

二、 在Jetty根目录的contexts下建立demo.xml(该文件名为了增加可读性最好与项目名相同)
demo.xml的内容如下:


<?xml version=”1.0″ encoding=”GB2312″?>
<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”>
<!– 配置一个WEB应用 –>
<Configure class=”org.mortbay.jetty.webapp.WebAppContext”>
<Set name=”contextPath”>/demo</Set>
<Set name=”resourceBase”>E:work应用服务器jetty-6.1.14jetty-6.1.14webappsdemo</Set>


<!– 创建数据源 –>
<New id=”ds” class=”org.apache.commons.dbcp.BasicDataSource”>
<Set name=”driverClassName”>com.mysql.jdbc.Driver</Set>
<Set name=”url”>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=gbk</Set>
<Set name=”username”>root</Set>
<Set name=”password”>123456</Set>
<Set name=”maxActive” type=”int”>100</Set>
<Set name=”maxIdle” type=”int”>30</Set>
<Set name=”maxWait” type=”int”>1000</Set>
<Set name=”defaultAutoCommit” type=”boolean”>true</Set>
<Set name=”removeAbandoned” type=”boolean”>true</Set>
<Set name=”removeAbandonedTimeout” type=”int”>60</Set>
<Set name=”logAbandoned” type=”boolean”>true</Set>
</New>

<!– 将实际的数据源绑定到 mysql2 这个 JNDI 名 –>
<New id=”mysql2″ class=”org.mortbay.jetty.plus.naming.Resource”>
<Arg>mysql2</Arg>
<Arg><Ref id=”ds”/></Arg>
</New>
</Configure>

三、修改应用下reportConfig.xml的数据源配置(目录WEB-INF)

<config>
<name>JNDIPrefix</name>
<value></value>
</config>

<!– 数据源名: mysql2,数据库类型:mysql,编码:GBK –>
<config>
<name>dataSource</name>
<value>mysql2,mysql,GBK;</value>
</config>

原文地址:https://www.cnblogs.com/shiGuangShiYi/p/10117561.html