当前位置: 首页 > 知识库问答 >
问题:

Spring、Hibernate和嵌入式derby-Jetty自动重新部署DB连接问题

端木骞尧
2023-03-14

我正在运行一个带有嵌入式derby Db的spring hibernate应用程序,并在jetty上通过自动重新部署运行它。现在,在执行自动重新部署时,我遇到了一个DB连接错误:

[INFO] restarting o.e.j.m.p.JettyWebAppContext@2f7a6e0e{/,file:/D:/aa/branches/dev/saas/src/main/webapp/,AVAILABLE}{file:/D:/aa/branches/dev/saas/src/main/webapp/}
2016-05-10 11:57:40.932:INFO:/:Scanner-0: Destroying Spring FrameworkServlet 'mvc-dispatcher'
2016-05-10 11:57:40 INFO  XmlWebApplicationContext:862 - Closing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Tue May 10 11:57:25 IST 2016]; root of context hierarchy
2016-05-10 11:57:40.967:INFO:oejsh.ContextHandler:Scanner-0: Stopped o.e.j.m.p.JettyWebAppContext@2f7a6e0e{/,file:/D:/aa/branches/dev/saas/src/main/webapp/,UNAVAILABLE}{file:/D:/aa/branches/dev/saas/src/main/webapp/}
[INFO] Webapp source directory = D:\aa\branches\dev\saas\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = D:\aa\branches\dev\saas\target\classes
[INFO] Context path = /
[INFO] Tmp directory = D:\aa\branches\dev\saas\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/D:/aa/branches/dev/saas/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = D:\aa\branches\dev\saas\src\main\webapp
2016-05-10 11:57:42.191:INFO:saas:Scanner-0: No Spring WebApplicationInitializer types detected on classpath
2016-05-10 11:57:42.322:INFO:saas:Scanner-0: Initializing Spring FrameworkServlet 'mvc-dispatcher'
2016-05-10 11:57:42 INFO  DispatcherServlet:484 - FrameworkServlet 'mvc-dispatcher': initialization started
2016-05-10 11:57:42 INFO  XmlWebApplicationContext:510 - Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Tue May 10 11:57:42 IST 2016]; root of context hierarchy
2016-05-10 11:57:42 INFO  XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
2016-05-10 11:57:42 INFO  PropertySourcesPlaceholderConfigurer:172 - Loading properties file from class path resource [application.properties]
2016-05-10 11:57:42 INFO  AutowiredAnnotationBeanPostProcessor:153 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-05-10 11:57:42 INFO  MLog:92 - MLog clients using log4j logging.
2016-05-10 11:57:42 INFO  C3P0Registry:216 - Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
2016-05-10 11:57:42 INFO  Version:66 - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-05-10 11:57:42 INFO  Version:54 - HHH000412: Hibernate Core {4.3.8.Final}
2016-05-10 11:57:42 INFO  Environment:239 - HHH000206: hibernate.properties not found
2016-05-10 11:57:42 INFO  Environment:346 - HHH000021: Bytecode provider name : javassist
2016-05-10 11:57:42 INFO  AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge0ws9g16jrn8m15ijs29|2a8c236e, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.apache.derby.jdbc.EmbeddedDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge0ws9g16jrn8m15ijs29|2a8c236e, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:derby:aaSaas;create=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
2016-05-10 11:58:13 WARN  BasicResourcePool:1851 - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@53b953ec -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
java.sql.SQLException: Failed to start database 'aaSaas' with class loader WebAppClassLoader=saas@5fce839, see the next exception for details.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
Caused by: ERROR XJ040: Failed to start database 'aaSaas' with class loader WebAppClassLoader=saas@5fce839, see the next exception for details.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
    ... 18 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database D:\aa\branches\dev\saas\aaSaas.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
    at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.FileMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.FileMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.FileMonitor.startModule(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
    at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source)
    at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
    at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source)
    ... 15 more
2016-05-10 11:58:13 WARN  BasicResourcePool:1851 - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@443e7c3e -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
java.sql.SQLException: Failed to create database 'aaSaas', see the next exception for details.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.createDatabase(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
Caused by: ERROR XJ041: Failed to create database 'aaSaas', see the next exception for details.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
    ... 18 more
Caused by: ERROR XBM0J: Directory D:\aa\branches\dev\saas\aaSaas already exists.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.services.monitor.StorageFactoryService$10.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.services.monitor.StorageFactoryService.createServiceRoot(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
    at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(Unknown Source)
    at org.apache.derby.impl.services.monitor.FileMonitor.createPersistentService(Unknown Source)
    at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Unknown Source)
    ... 15 more

现在我的问题是如何在重新部署时关闭连接,以便它可以创建一个新连接,或者我可以使用相同的连接吗?

mvc调度程序servlet。xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Specifying base package of the Components like Controller, Service, 
        DAO -->
    <context:component-scan base-package="com.aa.saas" />

    <!-- Getting Database properties -->
    <context:property-placeholder location="classpath:application.properties" />

    <mvc:annotation-driven />

    <!-- Specifying the Resource location to load JS, CSS, Images etc -->
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <!-- View Resolver <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
        <property name="prefix" value="/WEB-INF/pages/" /> <property name="suffix" 
        value=".jsp" /> </bean> -->

    <!-- DataSource -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
        <property name="driverClass" value="${database.driverClass}" />
        <property name="jdbcUrl" value="${database.url}" />
        <property name="user" value="${database.username}" />
        <property name="password" value="${database.password}" />
        <!-- <property name="acquireIncrement" value="${connection.acquireIncrement}" 
            /> <property name="minPoolSize" value="${connection.minPoolSize}" /> <property 
            name="maxPoolSize" value="${connection.maxPoolSize}" /> <property name="maxIdleTime" 
            value="${connection.maxIdleTime}" /> -->
    </bean>

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            </props>
        </property>
        <property name="packagesToScan" value="com.aa.saas"></property>
    </bean>

    <!-- Transaction -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="aaSaasUserDAO" class="com.aa.saas.aaSaasUserDAOImpl"></bean>

</beans>

网状物xml

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    id="WebApp_ID">
    <display-name>saas</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

</web-app>

应用属性

#Database related properties
database.driverClass=org.apache.derby.jdbc.EmbeddedDriver
database.url=jdbc:derby:aaSaas;create=true
database.username=aa
database.password=aa

#Hibernate related properties
hibernate.dialect=org.hibernate.dialect.DerbyDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true

#Connection pool related properties
#connection.acquireIncrement=2
#connection.minPoolSize=20
#connection.maxPoolSize=50
#connection.maxIdleTime=600

共有1个答案

宗政欣可
2023-03-14

哈林德,

我想你需要编辑一些代码。

读取错误消息。。

  1. 目录D:\aa\branchs\dev\saas\aaaas已经存在

derby文件夹中的delate文件夹(aaSaas)

        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop> 
            <prop key="hibernate.default_schema">test</prop>
            <prop key="hibernate.connection.pool_size">4</prop>
            <prop key="hibernate.connection.shutdown">true</prop>
            <prop key="hibernate.show_sql">true</prop> 
            <prop key="hibernate.hbm2ddl.auto">create</prop><!--delete all entity after create entity  -->
        </props>

嗯。。。

数据源

 <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> 
    <property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"></property> 
    <property name="username" value="user"></property> <property name="password" 
    value="1234"></property> <property name="url" value="jdbc:derby://localhost:1527/aaSaas;create=true"></property> 
    </bean>

我使用JPA和Derby。。在其他情况下。

嗯。。祝你好运

 类似资料:
  • 我的web应用程序(将部署在tomcat上)需要一个嵌入式数据库来存储临时用户数据,以便更快地检索。我选择Apache Embedded Derby是因为它很容易嵌入到web应用程序中,而且是一个纯Java DB。 我还实现了连接池来检索连接。我在这里面临着两个关键的问题(显示塞子)。首先,我的应用程序一次不能有两个以上的活动连接。所以,我的应用程序挂断了。 其次,我不断发现另一个应用程序已经启动

  • 我知道以前也有人问过类似的问题并回答过。但我试过了前面的答案的解决方案,但它们并不奏效。我已经尽我所能尝试了,希望有人能为我面临的问题提供一些启示。 在Spring Boot应用程序中配置嵌入式Derby 这是我的代码, 应用程序.属性 ApachederByExample.java 我只是试图在应用程序中使用Apache Derby嵌入式数据库,并且使用Maven中定义的依赖项,我不知道为什么仍

  • 问题内容: 我在使用ActiveMQ和Spring时遇到问题。我像这样设置它们: 正在使用故障转移传输: 我遇到的问题是,如果一个盒子掉了,我们应该开始在另一个盒子上发送消息,但是它似乎仍在使用旧的连接(每次发送都超时)。如果我重新启动该程序,它将再次连接并且一切正常。 我的理解是应该自行修复(重新连接到新盒子),并且每次都应请求新连接,因此应该可以。我想知道这是否可能做得不好(是否在缓存与旧服务

  • 我定义了一个标准的Maven webapp结构,它使用Spring MVC。 我正在使用嵌入式 Jetty 服务器(java 类)来测试开发中的应用程序。 用于创建 Jetty 服务器的代码概述如下。如果我对任何 JSP 文件进行更改,则这些更改将立即在浏览器中可见。 然而,如果我更改了任何类文件,例如控制器,这些更改不会被热部署。 我该怎么做才能让它工作? 我已经搜索了这个,我认为我需要使用类组

  • 我有一个Spring Boot应用程序,我使用ElasticsearchTemplate连接到我的ElasticSearch。然而,当它工作时,我关闭了Elasticsearch,每次我使用ElasticTemplate方法时,我都会得到一个组织。elasticsearch。客户运输NoNodeAvailableException。这很好,因为ElasticSearch不起作用。 然而,当Elas

  • 问题内容: 我想在 独立应用程序* 中将 hibernate 与 嵌入式derby 一起使用,并且我有一些问题: * 我需要什么jar? 必要的hibernate配置是什么? 还有其他必要的配置吗? 查询/条件是否有任何问题/限制? 如果您还可以建议我一些适合这种方法的好教程,那将是可取的,谢谢。 问题答案: 我将Apache Derby与Hibernate一起用于测试项目的一个模型类(它们的 e