将Jetty 6配置为使用commons.dbcp数据源

4

你好,我正在尝试配置Jetty 6.1.26使用连接池,但遇到了困难。

我将commons-dbcp-1.4.jarcommons-pool-1.5.6.jarmysql-connector-java-5.1.16放在我的Jetty/lib/ext文件夹中。

我还在我的Jetty/pom.xml文件中添加了对这些jar包的引用。

<dependencies>
   ...
   <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
  </dependency>
  <dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>1.5.6</version>
  </dependency>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.16</version>
  </dependency>
</dependencies>

在我的Eclipse Web项目中,我的jetty-env.xml文件(位于WEB-INF目录下)如下:
<Configure class="org.mortbay.jetty.webapp.WebAppContext">

<New id="MySQLDB" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>MySQLDB</Arg>
<Arg>
 <New class="org.apache.commons.dbcp.BasicDataSource">
    <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
    <Set name="url">jdbc:mysql://host_ip</Set>
    <Set name="username">user</Set>
    <Set name="password">pwd</Set>
    <Set name="auth">Container</Set>
    <Set name="maxActive">-1</Set>
    <Set name="maxIdle">30</Set>
    <Set name="maxWait">10000</Set>
    <Set name="minEvictableIdleTimeMillis">600000</Set>
    <Set name="name">MySQLDB</Set>
    <Set name="removeAbandoned">true</Set>
    <Set name="removeAbandonedTimeout">5000</Set>
    <Set name="timeBetweenEvictionRunsMillis">10000</Set>
    <Set name="type">javax.sql.DataSource</Set>
 </New>
</Arg>

</Configure>

然而,当我启动Jetty(在我的Jetty目录中使用java -jar start.jar)时,我遇到了以下异常:java.lang.NoSuchMethodException: class org.apache.commons.dbcp.BasicDataSource.setAuth(class java.lang.String)。我该如何正确设置Jetty?非常感谢!
2个回答

3
在你的代码中,你有一个 <Set name="auth">Container</Set> 的指令,它要求调用类的setAuth方法。但是该类并没有这样的方法。

@Femi 哦,对了。我真是太蠢了...现在它像魔法一样工作了。谢谢大家! - Mathieu

2

从配置中删除以下行:<Set name="auth">Container</Set><Set name="type">javax.sql.DataSource</Set>:异常告诉你这些功能在org.apache.commons.dbcp.BasicDataSource类中不存在。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接