org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session

4 篇文章 0 订阅
2 篇文章 0 订阅

报错信息如下:

org.springframework.transaction.CannotCreateTransactionException: 
Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
	at org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:542)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:377)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:461)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy39.getQuestionByNo(Unknown Source)
	at com.evaluationmanager.test.TypeTest.test(TypeTest.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
	at org.hibernate.internal.SessionImpl.connection(SessionImpl.java:524)
	at org.springframework.orm.hibernate5.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:448)
	... 37 more
	
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
	at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:73)
	at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
	... 40 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
	... 44 more
Caused by: java.sql.SQLException: No suitable driver
	at java.sql.DriverManager.getDriver(DriverManager.java:315)
	at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

我的配置配置:

db.properties

#data
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/evaluationmanager?characterEncoding=utf8
jdbc.username=root
jdbc.password=flzx3qc

# c3p0
c3p0.minPoolSize=3
c3p0.maxPoolSize=50
c3p0.initialPoolSize=5
c3p0.maxIdleTime=120
c3p0.acquireIncrement=5
c3p0.idleConnectionTestPeriod=60

# hibernate
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update
hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
hibernate.connection.autocommit=true
hibernate.javax.persistence.validation.mode=none
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider

applicationContext-hibernate.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans 
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	
	xsi:schemaLocation="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/aop 
 	       		 http://www.springframework.org/schema/aop/spring-aop.xsd">  
 	       		 
            <!-- default-autowire="byName" default-lazy-init="false"> -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:db/*.properties</value>
			</list>
		</property>
	</bean>
	<!-- c3p0数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}"/>  
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>
        <property name="minPoolSize" value="${c3p0.minPoolSize}"/>  
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>  
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>  
        <property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>  
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>  
        
        <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>  
	</bean>
	<!-- 配置sessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<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="hiberate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
				<prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
				<prop key="hiberate.javax.persistence.validation.mode">${hibernate.javax.persistence.validation.mode}</prop>
				
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
			</props>
		</property>
		<!-- 扫描实体类包 -->
		<property name="packagesToScan" value="com.evaluationmanager.entiy"></property>
	</bean>
	
	<!-- 配置hibernatTemplate 模板 -->
	 <bean id="hibernatTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
	 	<property name="sessionFactory" ref="sessionFactory"></property>
	 </bean>
	 <!-- 配置事务管理 --> 
	 <!-- transationManager -->
	 <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
	 	<property name="sessionFactory" ref="sessionFactory"></property>
	 </bean>
	 <!-- 开启事务注解 -->
	 <tx:annotation-driven transaction-manager="transactionManager"/>
 </beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans 
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	
	xsi:schemaLocation="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/aop 
 	       		 http://www.springframework.org/schema/aop/spring-aop.xsd">  
 	       		 
            <!-- default-autowire="byName" default-lazy-init="false"> -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:db/*.properties</value>
			</list>
		</property>
	</bean>
	<!-- c3p0数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}"/>  
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>
        <property name="minPoolSize" value="${c3p0.minPoolSize}"/>  
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>  
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>  
        <property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>  
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>  
        
        <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"/>  
	</bean>
	<!-- 配置sessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<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="hiberate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
				<prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
				<prop key="hiberate.javax.persistence.validation.mode">${hibernate.javax.persistence.validation.mode}</prop>
				
				<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
			</props>
		</property>
		<!-- 扫描实体类包 -->
		<property name="packagesToScan" value="com.evaluationmanager.entiy"></property>
	</bean>
	
	<!-- 配置hibernatTemplate 模板 -->
	 <bean id="hibernatTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
	 	<property name="sessionFactory" ref="sessionFactory"></property>
	 </bean>
	 <!-- 配置事务管理 --> 
	 <!-- transationManager -->
	 <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
	 	<property name="sessionFactory" ref="sessionFactory"></property>
	 </bean>
	 <!-- 开启事务注解 -->
	 <tx:annotation-driven transaction-manager="transactionManager"/>
 </beans>

解决分析:

项目之前没有配置c3p0连接池,sessionFactory配置的信息如上所示,之后加了c3p0之后,启动tomcat需要30多秒,启动不报错。

八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.SetAllPropertiesRule begin
警告: [SetAllPropertiesRule]{Server/Service/Connector} Setting property 'Encoding' to 'UTF-8' did not find a matching property.
八月 12, 2018 2:20:55 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:evaluationmanager' did not find a matching property.
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/7.0.82
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Sep 29 2017 12:23:15 UTC
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         7.0.82.0
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 10
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            10.0
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             C:\Program Files\Java\jdk1.8.0_66\jre
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.8.0_66-b17
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Oracle Corporation
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         D:\Program Files\eclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         D:\java-tool\apache-tomcat-7.0.82
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:51275
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\Program Files\eclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\java-tool\apache-tomcat-7.0.82
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\Program Files\eclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\java-tool\apache-tomcat-7.0.82\endorsed
八月 12, 2018 2:20:55 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=UTF-8
八月 12, 2018 2:20:55 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_66\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk1.8.0_66/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8.0_66/bin/../jre/bin;C:/Program Files/Java/jdk1.8.0_66/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.8.0_66\bin;C:\Program Files\Java\jdk1.8.0_66\jre\bin;C:\Program Files\Common Files\Autodesk Shared\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;D:\mysql\bin;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files (x86)\GtkSharp\2.12\bin;D:\study software\mysql\bin;D:\study software\mysql5.5\bin;D:\study software\mysql5_5\bin;D:\MyPath;D:\Program Files\MySQL\MySQL Server 5.5\bin;d:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;d:\Program Files\Microsoft SQL Server\100\Tools\Binn\;d:\Program Files\Microsoft SQL Server\100\DTS\Binn\;d:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;d:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\Program Files\mysql-5.7.21-winx64\bin;D:\Program Files\oracle;D:\java-tool\apache-maven-3.5.3\bin;D:\Program Files\Git\cmd;D:\Program Files\Git\bin;D:\Program Files\TortoiseSVN\bin;C:\Users\admin\AppData\Local\Microsoft\WindowsApps;;D:\study-software\Java\eclipse-jee-neon-2-win32-x86_64 (2)\eclipse;;.
八月 12, 2018 2:20:56 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
八月 12, 2018 2:20:56 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
八月 12, 2018 2:20:56 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 872 ms
八月 12, 2018 2:20:56 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
八月 12, 2018 2:20:56 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.82
八月 12, 2018 2:20:56 上午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [181] milliseconds.
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
八月 12, 2018 2:20:58 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
八月 12, 2018 2:20:58 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
八月 12, 2018 2:20:58 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
八月 12, 2018 2:21:33 上午 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [D:\Program Files\eclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\evaluationmanager\]
八月 12, 2018 2:21:33 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [classpath:log4j.properties]
八月 12, 2018 2:21:34 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
八月 12, 2018 2:21:34 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
八月 12, 2018 2:21:34 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 38717 ms

但是一访问页面,加载数据库数据需要很长时间,获取不到数据库数据。并且报错:

Connections could not be acquired from the underlying database!

后来经过半天折腾,将下图红色框内的配置删除之后,一切正常。可能是c3p0配置与下图的配置冲突吧,导致程序不加载,配置文件的配置信息,最终导致连接不上数据库。

 

 

### 回答1: org.springframework.transaction.cannotcreatetransactionexception: 无法为打开JDBC连接创建事务 这个异常通常是由于数据库连接池中的连接数已经达到了最大值,无法再创建新的连接导致的。解决方法可以增加数据库连接池的最大连接数,或者检查是否有未关闭的连接导致连接池中的连接数一直增加。另外,也可能是数据库服务出现了问题,需要检查数据库服务是否正常运行。 ### 回答2: org.springframework.transaction.cannotcreatetransactionexception: could not open jdbc connection for 错误是Spring框架在执行数据库事务时发生的一种异常。通常情况下,这个错误出现是因为数据库连接无法被建立,也就是无法访问数据库。 如果出现这个错误,我们需要检查以下几个因素: 1. 数据库连接池配置是否正确:Spring框架使用连接池来管理数据库连接,如果连接池的配置不正确,将无法从连接池中获取到可用的连接。需要确保连接池的相关配置信息正确,例如数据库地址、端口号、用户名及密码等。 2. 数据库是否正在运行:在一些情况下,数据库本身出现问题导致无法正常运行。需要确保数据库正在运行,或者尝试重启数据库服务。 3. 网络连接是否畅通:如果数据库服务器和应用服务器不在同一台机器上,需要确保网络连接畅通。也可以尝试ping数据库服务器的IP地址,检查网络连接是否正常。 4. 数据库连接数是否达到上限:如果数据库连接数达到了上限,新的连接请求将无法得到响应。需要检查数据库连接数是否达到了上限,并根据需要调整连接池的相关配置信息。 总之,org.springframework.transaction.cannotcreatetransactionexception: could not open jdbc connection for错误出现的原因有很多种。需要结合具体情况进行排查,以便及时解决问题。 ### 回答3: 这个错误是由于在使用Spring事务管理的过程中,无法打开JDBC连接所导致的。需要对这个错误进行排查才能解决。 首先,考虑JDBC连接的配置是否出现了问题。我们需要检查数据库的配置,确保数据库的连接信息正确(例如:url、用户名、密码、数据库驱动等)。如果有配置不正确或者连接不上数据库,就会出现该错误。 其次,考虑数据库的连接池是否出现了问题。在使用连接池时,需要设置合理的最大连接数及其它参数,以保证程序正常运行。如果连接池设置不当,可能会导致连接池无法提供可用连接,引发事务异常。 第三,检查数据库的状态。可能是因为数据库服务器崩溃或者数据库连接被意外断开等因素导致的无法连接到数据库。这时我们需要检查数据库服务器的状态,以及网络情况,确保能够正常连接到数据库。 最后,可以考虑增加日志输出,观察具体的异常信息,以确定问题的原因并进行解决。同时也需要加强对事务的管理和安全原则,以提高程序的稳定性和安全性。 总之,对于事务异常问题,我们需要针对错误提示进行具体的排查和解决。只有挖掘问题的深层原因并加以处理,才能真正解决问题,避免其再次发生。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值