新建文件jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.webapp.WebAppContext">
<New id="dbsource" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/boss</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">oracle.jdbc.driver.OracleDriver</Set>
<Set name="url">jdbc:oracle:thin:@ip:1521:oraclename</Set>
<Set name="username">username</Set>
<Set name="password">password</Set>
</New>
</Arg>
</New>
</Configure>
pom.xml中添加jetty依赖并设置jetty环境配置jetty.xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<encoding>UTF-8</encoding>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
<jettyEnvXml>src/main/resources/jetty.xml</jettyEnvXml>
</configuration>
</plugin>
springcontext.xml配置databaseSource
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
destroy-method="close">
<property name="jndiName">
<value>java:comp/env/jdbc/boss</value>
</property>
</bean>
当使用jetty中间件运行配置JNDI时,只需要将jetty.xml中的
1、Server~org.mortbay.jetty.webapp.WebAppContext
dbsource~org.mortbay.jetty.plus.naming.Resource
改成
Server~org.eclipse.jetty.webapp.WebAppContext
dbsource~org.eclipse.jetty.plus.jndi.Resource
2、将数据库依赖jar放到${JETTY_HOME}\lib\ext
参考
http://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource
http://www.eclipse.org/jetty/documentation/current/jetty-xml-config.html