fish3129 发表于 2017-2-27 11:24:49

jetty配置jndi数据源

  1.下载jetty服务器(8.1.0.RC2),解压到任意目录下
  http://dist.codehaus.org/jetty/jetty-hightide-8.1.0/jetty-hightide-8.1.0.RC2.zip
  2.新建jetty-dataSource.xml文件,放在${JETTY_HOME}\contexts目录下
  这个例子新建了两个mysql数据源,

<?xml version=&quot;1.0&quot;encoding=&quot;ISO-8859-1&quot;?>
<!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure.dtd&quot;>
<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test
Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.By specifying a context in this
directory, additional configuration may be specified and hot deployments
detected.
===================================================================== -->
<Configure class=&quot;org.eclipse.jetty.webapp.WebAppContext&quot;>
<Set name=&quot;contextPath&quot;>/datasource</Set>
<Set name=&quot;resourceBase&quot;>./</Set>
<New id=&quot;showcase&quot; class=&quot;org.eclipse.jetty.plus.jndi.Resource&quot;>
<Arg></Arg>
<Arg>jdbc/showcase</Arg>
<Arg>
<New class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;>
<Set name=&quot;driverClass&quot;>com.mysql.jdbc.Driver</Set>
<Set name=&quot;jdbcUrl&quot;>jdbc:mysql://localhost:3306/showcase?useUnicode=true&characterEncoding=UTF8</Set>
<Set name=&quot;user&quot;>root</Set>
<Set name=&quot;password&quot;>111111</Set>
</New>
</Arg>
</New>
<New id=&quot;quartz&quot; class=&quot;org.eclipse.jetty.plus.jndi.Resource&quot;>
<Arg></Arg>
<Arg>jdbc/quartz</Arg>
<Arg>
<New class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;>
<Set name=&quot;driverClass&quot;>com.mysql.jdbc.Driver</Set>
<Set name=&quot;jdbcUrl&quot;>jdbc:mysql://localhost:3306/quartz?useUnicode=true&characterEncoding=UTF8</Set>
<Set name=&quot;user&quot;>root</Set>
<Set name=&quot;password&quot;>111111</Set>
</New>
</Arg>
</New>
</Configure>3.将数据源用到的jar包放到${JETTY_HOME}\lib\ext目录下  因为以上用到了c3p0数据库连接池和mysql数据库,因此需要将mysql-connector-java-5.1.17.jar和c3p0-0.9.1.2.jar放到jetty容器的lib中
  4.重启jetty容器
  命令行到${JETTY_HOME}目录下,运行 java -jar start.jar启动容器
  5.附:常见的jndi数据库链接池配置
  参考:http://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource


  
页: [1]
查看完整版本: jetty配置jndi数据源