Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复c3p0连接池初始化异常?_Java_Servlets_Jdbc_Connection Pooling_C3p0 - Fatal编程技术网

Java 如何修复c3p0连接池初始化异常?

Java 如何修复c3p0连接池初始化异常?,java,servlets,jdbc,connection-pooling,c3p0,Java,Servlets,Jdbc,Connection Pooling,C3p0,这是我使用c3p0创建连接池时发生的异常 Jun 03, 2015 11:41:29 AM com.mchange.v2.log.MLog INFO: MLog clients using java 1.4+ standard logging. Jun 03, 2015 11:41:29 AM com.mchange.v2.c3p0.C3P0Registry INFO: Initializing c3p0-0.9.5 [built 02-January-2015 13:25:04 -0500

这是我使用c3p0创建连接池时发生的异常

Jun 03, 2015 11:41:29 AM com.mchange.v2.log.MLog 
INFO: MLog clients using java 1.4+ standard logging.
Jun 03, 2015 11:41:29 AM com.mchange.v2.c3p0.C3P0Registry 
INFO: Initializing c3p0-0.9.5 [built 02-January-2015 13:25:04 -0500; debug? true; trace: 10]
Jun 03, 2015 11:41:29 AM com.mchange.v2.c3p0.management.ActiveManagementCoordinator 
WARNING: A C3P0Registry mbean is already registered. This probably means that an application using c3p0 was undeployed, but not all PooledDataSources were closed prior to undeployment. This may lead to resource leaks over time. Please take care to close all PooledDataSources.
Jun 03, 2015 11:41:29 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource 
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge136991f2dudczsq8hw|458d8adc, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge136991f2dudczsq8hw|458d8adc, idleConnectionTestPeriod -> 300, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/ductoreh_patientdb, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, preferredTestQuery -> SELECT 1, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
Jun 03, 2015 11:42:02 AM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1629)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2161)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

Exception in thread "C3P0PooledConnectionPoolManager[identityToken->1hge136991f284clsmmfih|19faec40]-AdminTaskTimer" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1629)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2161)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    ... 5 more
Jun 03, 2015 11:42:18 AM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1629)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2161)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

Exception in thread "C3P0PooledConnectionPoolManager[identityToken->1hge136991f28gvv1q0gwo7|753c66d3]-AdminTaskTimer" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$AsyncTestIdleResourceTask
    at com.mchange.v2.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1629)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:2161)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    ... 5 more
这些是我用过的课程

-----连接和连接池---

----接口-------

---实现类----


在这里,我想知道这个例外是如何产生的,为什么?我可以完成我预期的任务,但这让我克服了错误。我是连接池的新手。

您好,在我工作的一个应用程序中,我遇到了相同的异常。下面是我遇到类似问题时参考的一些有用链接:

[1]

[2]


在重新部署过程中,类被卸载,如果您未能关闭Hibernate的sessionFactory,则会出现这些ClassNotFound错误。#2中的一个答案建议您可以添加一个自定义ServletContextListener来处理contextDestroyed事件。

我在一个Maven项目中遇到了同样的问题,当时正在处理这个问题两周;它在Eclipse中工作,但在Ubuntu服务器中不工作。谷歌搜索的所有解决方案都不起作用

在我的例子中,解决了将hibernate核心和c3p0库添加到我的pom中的问题(项目已经有了hibernate-c3p0库)

这是我添加的pom.xml代码:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.12.Final</version>
        <exclusions>
        <exclusion>
            <artifactId>jta</artifactId>
            <groupId>javax.transaction</groupId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

org.hibernate
冬眠核心
5.2.12.最终版本
jta
javax.transaction
org.slf4j
slf4j api
dom4j
dom4j

希望它能帮助别人!:)

类路径中是否有
c3po.jar
?如果是,请选择哪个版本?@Jens c3p0-0.9.5.jar并且这个jar在运行时位于您的类路径中?@Jens是的,我有它。谢谢您的帮助,但我在这项工作中没有使用hibernate。
public interface DBInterface
{
    public List<UserBean> getUserData();
}
public class UserBean
{
    private int idUser;
    private String companyName;
    private String country;
    private String adressLine1;
    private String addressLine2;
    private String zip;
    private String phone;
    private String email;
    private boolean isTrial;
    private Timestamp dateCreated;
    private Timestamp lastUpdated;

    /**
     * @return the idUser
     */
    public int getIdUser()
    {
        return idUser;
    }

    /**
     * @param idUser the idUser to set
     */
    public void setIdUser(int idUser)
    {
        this.idUser = idUser;
    }

    /**
     * @return the companyName
     */
    public String getCompanyName()
    {
        return companyName;
    }

    /**
     * @param companyName the companyName to set
     */
    public void setCompanyName(String companyName)
    {
        this.companyName = companyName;
    }

    /**
     * @return the country
     */
    public String getCountry()
    {
        return country;
    }

    /**
     * @param country the country to set
     */
    public void setCountry(String country)
    {
        this.country = country;
    }

    /**
     * @return the adressLine1
     */
    public String getAdressLine1()
    {
        return adressLine1;
    }

    /**
     * @param adressLine1 the adressLine1 to set
     */
    public void setAdressLine1(String adressLine1)
    {
        this.adressLine1 = adressLine1;
    }

    /**
     * @return the addressLine2
     */
    public String getAddressLine2()
    {
        return addressLine2;
    }

    /**
     * @param addressLine2 the addressLine2 to set
     */
    public void setAddressLine2(String addressLine2)
    {
        this.addressLine2 = addressLine2;
    }

    /**
     * @return the zip
     */
    public String getZip()
    {
        return zip;
    }

    /**
     * @param zip the zip to set
     */
    public void setZip(String zip)
    {
        this.zip = zip;
    }

    /**
     * @return the phone
     */
    public String getPhone()
    {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    /**
     * @return the email
     */
    public String getEmail()
    {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email)
    {
        this.email = email;
    }

    /**
     * @return the isTrial
     */
    public boolean isIsTrial()
    {
        return isTrial;
    }

    /**
     * @param isTrial the isTrial to set
     */
    public void setIsTrial(boolean isTrial)
    {
        this.isTrial = isTrial;
    }

    /**
     * @return the dateCreated
     */
    public Timestamp getDateCreated()
    {
        return dateCreated;
    }

    /**
     * @param dateCreated the dateCreated to set
     */
    public void setDateCreated(Timestamp dateCreated)
    {
        this.dateCreated = dateCreated;
    }

    /**
     * @return the lastUpdated
     */
    public Timestamp getLastUpdated()
    {
        return lastUpdated;
    }

    /**
     * @param lastUpdated the lastUpdated to set
     */
    public void setLastUpdated(Timestamp lastUpdated)
    {
        this.lastUpdated = lastUpdated;
    }


}
public class DBImpl implements DBInterface
{

    public List<UserBean> getUserData()
    {
        System.out.println("01");

        Statement statement=null;
        Connection connection=null;
        ResultSet resultSet=null;
        List<UserBean> beans=new ArrayList<UserBean>();

        System.out.println("02");
        try
        {
            System.out.println("03");
            connection=DBConnection.getInstance().getConnection();
            System.out.println("04");
            String sql = "select * from user where isTrial=true";
            System.out.println("05");
            statement=connection.createStatement();
            System.out.println("06");
            resultSet=statement.executeQuery(sql.toLowerCase());
            System.out.println("07");
            if(resultSet.isBeforeFirst())
            {
                System.out.println("08");
                while(resultSet.next()){
                    System.out.println("09");
                    UserBean bean=new UserBean();
                    System.out.println("10");

                    bean.setIdUser(resultSet.getInt("idUser"));
                    System.out.println(resultSet.getInt("idUser"));

                    bean.setCompanyName(resultSet.getString("CompanyName"));
                    System.out.println(resultSet.getString("CompanyName"));

                    bean.setCountry(resultSet.getString("Country"));
                    bean.setAdressLine1(resultSet.getString("Address_Line1"));
                    bean.setAddressLine2(resultSet.getString("Address_Line2"));
                    bean.setZip(resultSet.getString("Zip"));
                    bean.setPhone(resultSet.getString("Phone"));
                    bean.setEmail(resultSet.getString("Email"));
                    bean.setIsTrial(resultSet.getBoolean("isTrial"));
                    bean.setDateCreated(resultSet.getTimestamp("DateCreated"));
                    bean.setLastUpdated(resultSet.getTimestamp("LastUpdated"));
                    beans.add(bean);
                }
            }


        } catch (Exception ex)
        {
            ex.printStackTrace();
        }finally{
            try{
                if(resultSet!=null){
                    resultSet.close();
                }
                if(statement!=null){
                    statement.close();
                }
                if(connection!=null){
                    connection.close();
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }

        return beans;

    }


}
public class Test01 extends HttpServlet
{

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try
        {
            DBInterface bImpl=new DBImpl();            
            List<UserBean> userData = bImpl.getUserData();            

            for(int i=0;i<userData.size();i++){
                out.println(userData.get(i).toString());
            }


        } finally
        {
            out.close();
        }
    }
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.12.Final</version>
        <exclusions>
        <exclusion>
            <artifactId>jta</artifactId>
            <groupId>javax.transaction</groupId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>