Frage Verbindungspooling mit Jetty in Oracle


Ich versuche das Konzept von zu implementieren ConnectionPooling im Oracle verwenden Jetty Server. Ich habe folgendes versucht, was ich in einem Tutorial gesehen habe. Es funktioniert, wenn ich mit bereitstellen Tomcat Server, aber Jetty scheint mir ungewöhnlich zu sein error. Details sind unten -

Ich habe eine Klasse namens TestServlet.java definiert als -

import java.io.IOException;
import java.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.sql.DataSource;


@SuppressWarnings("serial")
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
public TestServlet() throws ServletException{
    System.out.println("Constructor");
    init();
}
public DataSource dataSource;
private Connection con;
private Statement statement;

public void init() throws ServletException {
    System.out.println("inside init method");
    try {
        // Get DataSource
        Context initContext  = new InitialContext();
        System.out.println("Before envcontext");
        Context envContext  = (Context)initContext.lookup("java:comp/env");
        System.out.println("After envcontext");
        dataSource = (DataSource)envContext.lookup("jdbc/DSTest");
        System.out.println(dataSource.toString());
    } catch (NamingException e) {
        System.out.println("Exception in try");
        e.printStackTrace();
    }
}

public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    System.out.println("Request: "+req+"\tResponse: "+resp);
     int i=0;
    ResultSet resultSet = null;
    try {
        // Get Connection and Statement
        con = dataSource.getConnection();
        statement = con.createStatement();
        String query = "SELECT * FROM USER";
        resultSet = statement.executeQuery(query);
        while (resultSet.next()) {
            ++i;
            System.out.println(i+":\nID:"+resultSet.getString("ID") +"\nEmail:"+ resultSet.getString("UEMAIL") +"\nPassword:" + resultSet.getString("PASSWORD")+"\nFlag:"+resultSet.getShort("FLAG")
                    +"\n");

        }
    } catch (SQLException e) {
        System.out.println("EXCEPTIOn");
        e.printStackTrace();
    }finally {
        try { if(null!=resultSet)resultSet.close();} catch (SQLException e) 
        {e.printStackTrace();System.out.println("1");}
        try { if(null!=statement)statement.close();} catch (SQLException e) 
        {e.printStackTrace();System.out.println("2");}
        try { if(null!=con)con.close();} catch (SQLException e) 
        {e.printStackTrace();System.out.println("3");}
    }
}

}

Und mein Jetty-web.xml ist als -

<?xml version="1.0" encoding="UTF-8"?>
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
 <Arg>java:comp/env</Arg>
 <Arg>jdbc/DSTest</Arg>
 <Arg>
     <New class="org.apache.commons.dbcp.BasicDataSource">
        <Set name="driverClassName">oracle.jdbc.OracleDriver</Set>
        <Set  name="url">ConnectionUrl</Set>
        <Set name="username">app_user</Set>
        <Set name="password">abcd</Set>
     </New>
 </Arg>
</New>
</Configure>

Wenn ich renne servlet Klasse Ich bekomme einen Fehler, der sagt -

java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:748)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1078)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:993)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:741)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:383)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:317)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:276)
at org.eclipse.jetty.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:100)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at runjettyrun.Bootstrap.main(Bootstrap.java:80)
Caused by: 
java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
at runjettyrun.ProjectClassLoader.loadClass(ProjectClassLoader.java:92)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:748)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1078)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:993)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:741)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:383)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:317)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:276)
at org.eclipse.jetty.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:100)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at runjettyrun.Bootstrap.main(Bootstrap.java:80)
2015-10-30 14:22:51.172:INFO:oejs.AbstractConnector:Started     SelectChannelConnector@0.0.0.0:8081 STARTING
2015-10-30 14:22:51.172:WARN:oejuc.AbstractLifeCycle:FAILED   org.eclipse.jetty.server.Server@7857fe2: java.lang.NoClassDefFoundError:   org/apache/commons/pool/impl/GenericObjectPool
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:748)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1078)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:993)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:741)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:383)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:317)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:276)
at org.eclipse.jetty.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:100)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at runjettyrun.Bootstrap.main(Bootstrap.java:80)
Caused by: 
java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
at runjettyrun.ProjectClassLoader.loadClass(ProjectClassLoader.java:92)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:748)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1078)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:993)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:741)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:383)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:317)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:276)
at org.eclipse.jetty.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:100)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at runjettyrun.Bootstrap.main(Bootstrap.java:80)
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
at java.lang.Class.getConstructors(Class.java:1638)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:748)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1078)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:993)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:741)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:383)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:317)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:276)
at org.eclipse.jetty.webapp.JettyWebXmlConfiguration.configure(JettyWebXmlConfiguration.java:100)
at org.eclipse.jetty.webapp.WebAppContext.configure(WebAppContext.java:427)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1207)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
at runjettyrun.Bootstrap.main(Bootstrap.java:80)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:415)
at runjettyrun.ProjectClassLoader.loadClass(ProjectClassLoader.java:92)
... 20 more

Ich habe das hinzugefügt commons-dbcp-1.4.jar zu meinem WEB-INF/lib Ordner in Eclipse nach dem Blick auf andere Stackoverflow-Threads. Selbst nachdem ich dies getan habe, erhalte ich den gleichen Fehler, wenn ich das Deployment ausführe Jetty.

ich benutze jetty Server Version 8 integriert mit eclipse luna 4.4.1.

Jede Hilfe wird sehr geschätzt.


6
2017-10-30 07:22


Ursprung


Antworten:


Du hast 3 Möglichkeiten, es zu tun:

  1. Wenn Sie Maven oder Gradle in Ihrem Projekt verwenden, fügen Sie einfach eine commons-pool-Abhängigkeit zu Ihrer pom.xml- oder build.gradle-Datei hinzu (empfohlene Methode)
  2. Wenn Sie eines der genannten Tools nicht verwenden, setzen Sie das richtige jar in das Verzeichnis WEB-INF / lib
  3. Das letzte ist, das jar im Verzeichnis $ {jettyHome} / lib zu platzieren

Stellen Sie sicher, dass Sie die korrekte Version des Commons-Pools für Ihre aktuelle commons-dbcp-Implementierung verwenden


5
2017-11-05 22:46



Sie benutzen nicht einfach Tomcat. finde es hier http://tomcat.apache.org/ :) Hinweis Dieser Steg kann nur gut genutzt werden, wenn Sie die lokale App-Entwicklung vereinfachen müssen. https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html Ich schlage vor, Sie fangen an, die Grundlagen zu lesen tomcat Und wenn Sie anfangen, ein grundlegendes Verständnis dafür zu bekommen, wie die Dinge funktionieren, sollten Sie mit der Implementierung beginnen Connection Pooling :) Hoffe das hilft.


2
2017-11-10 08:59



Wenn ich einen Oracle-Verbindungspool brauche, verwende ich immer ojdbcx.jar mit ucp.jar. Sie können sie von herunterladen Hier.

Sie können Tonnen von How-tos von Google finden, aber es gibt ein einfaches (für Jetty 6) Hier.


-1
2017-11-10 20:58