spring3.0整合异常,我的框架为struts2.1+hibernate3.0+spring3.0+mysql5.0+tomcat6.0
org.springframework.transaction.CannotCreateTransactionException:CouldnotopenHibernat...
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection
上面的是异常信息,也就是没能打开session,applicationContext.xml,application.local.properties配置文件如下,使用的是注解管理sessionFactory,没有使用映射文件,POJO用的是注解映射,如下:
<!-- 数据源配置,使用应用内的c3p0数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${database.driverClass}"/>
<property name="jdbcUrl" value="${database.jdbcUrl}"/>
<property name="user" value="${database.user}"/>
<property name="password" value="${database.password}"/>
<property name="acquireIncrement" value="1"/>
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="10"/>
<property name="maxIdleTime" value="600"/>
<property name="maxStatements" value="0"/>
</bean>
<!-- Hibernate配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}</prop>
<!--
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
-->
</props>
</property>
<property name="packagesToScan" value="com.zeng.beiliu.entity.*"/>
</bean>
<!-- 事务管理器配置,单数据源事务 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
application.local.properties
#----MySQL-----#
database.driverClass=com.mysql.jdbc.Driver
database.jdbcUrl=jdbc\:mysql\://localhost\:3306/zengchao
database.user=root
database.password=123456
#hibernate settings
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.max_fetch_depth=2
hibernate.connection.release_mode=auto
hibernate.hbm2ddl.auto=create
hibernate.temp.use_jdbc_metadata_defaults=false
大家给个意见,问题可能出在哪,在页面上不好说清楚的,可以在线交流 展开
上面的是异常信息,也就是没能打开session,applicationContext.xml,application.local.properties配置文件如下,使用的是注解管理sessionFactory,没有使用映射文件,POJO用的是注解映射,如下:
<!-- 数据源配置,使用应用内的c3p0数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${database.driverClass}"/>
<property name="jdbcUrl" value="${database.jdbcUrl}"/>
<property name="user" value="${database.user}"/>
<property name="password" value="${database.password}"/>
<property name="acquireIncrement" value="1"/>
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="10"/>
<property name="maxIdleTime" value="600"/>
<property name="maxStatements" value="0"/>
</bean>
<!-- Hibernate配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}</prop>
<!--
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
-->
</props>
</property>
<property name="packagesToScan" value="com.zeng.beiliu.entity.*"/>
</bean>
<!-- 事务管理器配置,单数据源事务 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
application.local.properties
#----MySQL-----#
database.driverClass=com.mysql.jdbc.Driver
database.jdbcUrl=jdbc\:mysql\://localhost\:3306/zengchao
database.user=root
database.password=123456
#hibernate settings
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.max_fetch_depth=2
hibernate.connection.release_mode=auto
hibernate.hbm2ddl.auto=create
hibernate.temp.use_jdbc_metadata_defaults=false
大家给个意见,问题可能出在哪,在页面上不好说清楚的,可以在线交流 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询