简体   繁体   中英

Configuring Jetty 6 to use commons.dbcp datasource

Hi I'm trying to configure Jetty 6.1.26 to use connection pooling and it's giving me a hard time.

I put commons-dbcp-1.4.jar , commons-pool-1.5.6.jar and mysql-connector-java-5.1.16 in my Jetty/lib/ext folder.

I also added references to those jars in my Jetty/pom.xml

<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>

In my web project in eclipse, my jetty-env.xml (in WEB-INF) file is like this:

<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>

However, when I start Jetty (using java -jar start.jar in my Jetty directory), I get this exception:

java.lang.NoSuchMethodException: class org.apache.commons.dbcp.BasicDataSource.setAuth(class java.lang.String)

How can I setup Jetty correctly? Thanks alot!

In your code you have <Set name="auth">Container</Set> the instruction says to call the method setAuth of the class. But the class doesn't have anything like that.

Remove the lines <Set name="auth">Container</Set> and <Set name="type">javax.sql.DataSource</Set> from the configuration: the exception is telling you that those functions don't exist on the org.apache.commons.dbcp.BasicDataSource class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM