第一次搭建spring 时踩得坑Could not open JDBC Connection for transaction

第一次搭建spring 时遇到以下错误。初次接触java ,看错误信息还不是很熟练,定位问题比较费力。开始以为是包引入的有问题,最后无意中发现是 mysql端口号错误。

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

应当看这里的错误信息

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:245)

at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)

at org.springframework.test.context.transaction.TransactionContext.startTransaction(TransactionContext.java:98)

at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:194)

at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:265)

at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextBeforeTestMethod(AbstractTestNGSpringContextTests.java:162)

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:498)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)

at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)

at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

at org.testng.TestRunner.privateRun(TestRunner.java:767)

at org.testng.TestRunner.run(TestRunner.java:617)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)

at org.testng.SuiteRunner.run(SuiteRunner.java:240)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)

at org.testng.TestNG.run(TestNG.java:1057)

at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)

at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

    原文作者:三好大师
    原文地址: https://zhuanlan.zhihu.com/p/32102376
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞