Java 连接池和数据库创建上的Hibernate和Spring集成错误
我正在尝试制作一个集成Spring和Hibernate的web应用程序。我得到的不是一个例外,但我的日志继续生成消息,在我看来,这些消息强调了db generation\connection中的一个问题。我声明了一个可以由hsql swing管理器访问的hsql数据库,但db文件在文件资源管理器中不可见。我得到的不是test.db,而是以下文件:Java 连接池和数据库创建上的Hibernate和Spring集成错误,java,xml,spring,hibernate,spring-mvc,Java,Xml,Spring,Hibernate,Spring Mvc,我正在尝试制作一个集成Spring和Hibernate的web应用程序。我得到的不是一个例外,但我的日志继续生成消息,在我看来,这些消息强调了db generation\connection中的一个问题。我声明了一个可以由hsql swing管理器访问的hsql数据库,但db文件在文件资源管理器中不可见。我得到的不是test.db,而是以下文件: testdb.lck testdb.log testdb.properties testdb.script 日志警告是以下消息;在谷歌上搜索似乎不
- testdb.lck
- testdb.log
- testdb.properties
- testdb.script
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1550) - BEGIN check for expired resources. [com.mchange.v2.resourcepool.BasicResourcePool@788c1852]
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1632) - EXPIRED idle resource: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6 ---> idle_time: 8513; max_idle_time: 7000 [com.mchange.v2.resourcepool.BasicResourcePool@788c1852]
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1561) - Removing expired resource: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6 [com.mchange.v2.resourcepool.BasicResourcePool@788c1852]
17/06/2015 16:04:11 - DEBUG - (ThreadPoolAsynchronousRunner.java:236) - com.mchange.v2.async.ThreadPoolAsynchronousRunner@60eb9f58: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@31b75e54
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1022) - Preparing to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1747) - trace com.mchange.v2.resourcepool.BasicResourcePool@788c1852 [managed: 1, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@a62b39f)
17/06/2015 16:04:11 - DEBUG - (C3P0PooledConnectionPool.java:616) - Preparing to destroy PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1747) - trace com.mchange.v2.resourcepool.BasicResourcePool@788c1852 [managed: 1, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@a62b39f)
17/06/2015 16:04:11 - DEBUG - (GooGooStatementCache.java:355) - ENTER METHOD: closeAll( org.hsqldb.jdbc.JDBCConnection@4795dda9 )! -- num_connections: 0
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1571) - FINISHED check for expired resources. [com.mchange.v2.resourcepool.BasicResourcePool@788c1852]
17/06/2015 16:04:11 - DEBUG - (GooGooStatementCache.java:394) - closeAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:450) - incremented pending_acquires: 1
17/06/2015 16:04:11 - DEBUG - (NewPooledConnection.java:646) - com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6 closed by a client.
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:646)
at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:259)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:619)
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1024)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
17/06/2015 16:04:11 - DEBUG - (C3P0PooledConnectionPool.java:627) - Successfully destroyed PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1788) - Starting acquisition series. Incremented pending_acquires [1], attempts_remaining: 30
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1027) - Successfully destroyed resource: com.mchange.v2.c3p0.impl.NewPooledConnection@400ba6f6
17/06/2015 16:04:11 - DEBUG - (ThreadPoolAsynchronousRunner.java:236) - com.mchange.v2.async.ThreadPoolAsynchronousRunner@60eb9f58: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@7d91f64b
17/06/2015 16:04:11 - DEBUG - (GooGooStatementCache.java:333) - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 0; checked out: 0; num connections: 0; num keys: 0
17/06/2015 16:04:11 - DEBUG - (C3P0PooledConnectionPool.java:283) - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@49833c9c.acquireResource() returning.
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1747) - trace com.mchange.v2.resourcepool.BasicResourcePool@788c1852 [managed: 2, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@a62b39f)
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:471) - decremented pending_acquires: 0
17/06/2015 16:04:11 - DEBUG - (BasicResourcePool.java:1825) - Acquisition series terminated successfully. Decremented pending_acquires [0], attempts_remaining: 30
这个消息似乎重复了endlessy
我的配置文件是:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Fantacalcio</display-name>
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-database.xml,WEB-INF/spring-mvc-servlet.xml</param-value>
</context-param>
</web-app>
范塔卡西奥
春季mvc
org.springframework.web.servlet.DispatcherServlet
1.
春季mvc
/
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/spring database.xml,WEB-INF/spring-mvc-servlet.xml
spring-mvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/pages/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<tx:annotation-driven />
<context:component-scan base-package="org.fabrizio.fantacalcio.controller" />
</beans:beans>
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:file:C:\\hsqldb-2.3.2\\hsqldb\\test.db</property>
<property name="hibernate.connection.username">SA</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.jdbc.batch_size">1000</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.timeout">7</property> <!-- secondi -->
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property><!-- millisecondi -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">false</property>
<property name="hibernate.c3p0.checkoutTimeout">2000</property><!-- millisecondi -->
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- <property name="hibernate.current_session_context_class">thread</property>-->
<property name="hibernate.id.new_generator_mappings">true</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.generate_statistics">true</property>
<mapping class="org.fabrizio.fantacalcio.model.beans.Utente"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.Ruolo"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.Calciatore"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.Formazione"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.Partita"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.Scontro"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.SquadraFantacalcio"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.SquadraReale"/>
<mapping class="org.fabrizio.fantacalcio.model.beans.StagioneFantacalcio"/>
</session-factory>
</hibernate-configuration>
org.hsqldb.jdbcDriver
jdbc:hsqldb:file:C:\\hsqldb-2.3.2\\hsqldb\\test.db
沙特阿拉伯
1000
org.hibernate.dialogue.hsql方言
更新
org.hibernate.c3p0.internal.C3P0ConnectionProvider
2.
10
7.
10
3000
1.
假的
2000
假的
org.hibernate.cache.NoCacheProvider
真的
假的
真的
真的
真的
真的
spring-database.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="configLocation" value="classpath:hibernate.cfg.xml" />
</beans:bean>
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
</beans:beans>
很抱歉代码的格式设置,但它似乎不太喜欢xml,希望有人能编辑我的消息。你真的看过你的日志了吗?它没有生成错误,只是生成了一条调试消息。好的,这不是错误,但该消息会稍微提醒我一点。并且数据库文件没有生成。对于初学者,停止加载应用程序两次。。。通过
DispatcherServlet
和ContextLoaderListener
加载相同的配置,可以有效地加载整个应用程序两次。Nexttestdb
和test.db
既不是打字错误,也不是指向错误的文件。如果我删除web.xml中的ContextLoaderListener
声明,应用程序将启动,但hibernate甚至不尝试创建db,spring也不会实例化bean。顺便说一下,数据库名称错误只是一个输入错误,我使用的每个名称都会导致生成我之前说过的文件,但是数据库文件没有生成。很明显,因为现在只加载mvc的东西。您应该从ContextLoaderListener
加载的文件中删除WEB-INF/spring mvc servlet.xm
。