平台:eclipse neon + springmvc + jpa + maven springframework 4.3 当我使用JUnit Test时,代码没问题,控制台显示正确的结果,控制台显示详细信息:
19:01:43.491 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@71c8becc, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@19d37183, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1a0dcaa, org.springframework.test.context.support.DirtiesContextTestExecutionListener@3bd40a57, org.springframework.test.context.transaction.TransactionalTestExecutionListener@fdefd3f, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@d83da2e]
19:01:43.504 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@78e94dcf, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@233fe9b6, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@358ee631, org.springframework.test.context.support.DirtiesContextTestExecutionListener@ec756bd, org.springframework.test.context.transaction.TransactionalTestExecutionListener@3c72f59f, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@60dcc9fe]
19:01:43.553 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
19:01:43.844 [main] INFO o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Skipped XML bean definition file due to specified profiles [production] not matching: class path resource [applicationContext.xml]
19:01:43.846 [main] INFO o.s.c.s.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@48aaecc3: startup date [Fri Apr 21 19:01:43 CST 2017]; root of context hierarchy
19:01:44.219 [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
19:01:49.654 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
19:01:49.670 [main] INFO o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: default
...]
19:01:49.766 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.2.10.Final}
19:01:49.768 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
19:01:49.799 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
19:01:49.908 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.DB2Dialect
19:01:49.979 [main] INFO o.h.e.j.e.i.LobCreatorBuilderImpl - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
19:01:50.255 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.4.1.Final
19:01:50.602 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
19:01:50.820 [main] INFO o.h.h.i.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
19:01:50.941 [main] INFO o.s.aop.framework.CglibAopProxy - Unable to proxy method [public final void org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests.setApplicationContext(org.springframework.context.ApplicationContext)] because it is final: All calls to this method via a proxy will NOT be routed to the target instance.
19:01:51.017 [main] INFO o.s.t.c.t.TransactionContext - Began transaction (1) for test context [DefaultTestContext@1e0fdb2f testClass = TdFinaacctMainDaoTest, testInstance = org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest@3c380bd8, testMethod = findFinaacctA@TdFinaacctMainDaoTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@6fc1020a testClass = TdFinaacctMainDaoTest, locations = '{classpath:/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@2c413ffc]; rollback [true]
19:01:51.147 [main] INFO o.s.t.c.t.TransactionContext - Rolled back transaction for test context [DefaultTestContext@1e0fdb2f testClass = TdFinaacctMainDaoTest, testInstance = org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest@3c380bd8, testMethod = findFinaacctA@TdFinaacctMainDaoTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@6fc1020a testClass = TdFinaacctMainDaoTest, locations = '{classpath:/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].
19:01:51.153 [main] INFO o.s.aop.framework.CglibAopProxy - Unable to proxy method [public final void org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests.setApplicationContext(org.springframework.context.ApplicationContext)] because it is final: All calls to this method via a proxy will NOT be routed to the target instance.
19:01:51.166 [main] INFO o.s.t.c.t.TransactionContext - Began transaction (1) for test context [DefaultTestContext@7f7b6639 testClass = JpaMappingTest, testInstance = org.pbc.qzgk.tbdp.repository.JpaMappingTest@16ac5d35, testMethod = allClassMapping@JpaMappingTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@18a19e testClass = JpaMappingTest, locations = '{classpath:/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@2c413ffc]; rollback [true]
19:01:51.167 [main] INFO o.p.q.tbdp.repository.JpaMappingTest - first step
19:01:51.171 [main] INFO o.p.q.tbdp.repository.JpaMappingTest - second step
19:01:51.171 [main] INFO o.p.q.tbdp.repository.JpaMappingTest - third step
19:01:51.277 [main] INFO o.p.q.tbdp.repository.JpaMappingTest - ok: TdFinaacctMain
19:01:51.277 [main] INFO o.p.q.tbdp.repository.JpaMappingTest - fourth step
19:01:51.281 [main] INFO o.s.t.c.t.TransactionContext - Rolled back transaction for test context [DefaultTestContext@7f7b6639 testClass = JpaMappingTest, testInstance = org.pbc.qzgk.tbdp.repository.JpaMappingTest@16ac5d35, testMethod = allClassMapping@JpaMappingTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@18a19e testClass = JpaMappingTest, locations = '{classpath:/applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].
19:01:51.283 [Thread-1] INFO o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@48aaecc3: startup date [Fri Apr 21 19:01:43 CST 2017]; root of context hierarchy
19:01:51.285 [Thread-1] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
19:01:51.290 [Thread-1] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closed
2.当我使用maven测试时,控制台会显示以下错误:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
19:03:22.107 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@31368b99, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1725dc0f, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3911c2a7, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4ac3c60d, org.springframework.test.context.transaction.TransactionalTestExecutionListener@4facf68f, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@76508ed1]
19:03:22.115 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@7714e963, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@20ce78ec, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@393671df, org.springframework.test.context.support.DirtiesContextTestExecutionListener@56620197, org.springframework.test.context.transaction.TransactionalTestExecutionListener@6eda5c9, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@55b7a4e0]
19:03:22.158 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
19:03:22.456 [main] INFO o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Skipped XML bean definition file due to specified profiles [production] not matching: class path resource [applicationContext.xml]
19:03:22.458 [main] INFO o.s.c.s.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@36bc55de: startup date [Fri Apr 21 19:03:22 CST 2017]; root of context hierarchy
19:03:22.754 [main] ERROR c.alibaba.druid.pool.DruidDataSource - {dataSource-1} init error
19:03:22.756 [main] WARN o.s.c.s.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
19:03:22.758 [main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3911c2a7] to prepare test instance [org.pbc.qzgk.tbdp.repository.JpaMappingTest@6986bbaf]
[INFO] Running org.pbc.qzgk.tbdp.repository.JpaMappingTest
19:03:22.767 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
19:03:22.818 [main] INFO o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Skipped XML bean definition file due to specified profiles [production] not matching: class path resource [applicationContext.xml]
19:03:22.820 [main] INFO o.s.c.s.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@6127a7e: startup date [Fri Apr 21 19:03:22 CST 2017]; root of context hierarchy
19:03:22.867 [main] ERROR c.alibaba.druid.pool.DruidDataSource - {dataSource-2} init error
19:03:22.869 [main] WARN o.s.c.s.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
19:03:22.872 [main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@393671df] to prepare test instance [org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest@5a9d6f02]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
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.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:107)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:83)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:157)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 36 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 54 common frames omitted
Caused by: java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:570)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:697)
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.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1695)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 61 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:568)
... 69 common frames omitted
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.113 s <<< FAILURE! - in org.pbc.qzgk.tbdp.repository.JpaMappingTest
[ERROR] allClassMapping(org.pbc.qzgk.tbdp.repository.JpaMappingTest) Time elapsed: 0.003 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
[INFO] Running org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.001 s <<< FAILURE! - in org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest
[ERROR] findFinaacctA(org.pbc.qzgk.tbdp.repository.syspara.TdFinaacctMainDaoTest) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: java.sql.SQLException: com.ibm.db2.jcc.DB2Driver
Caused by: java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
答案 0 :(得分:0)
引起:java.lang.ClassNotFoundException:com.ibm.db2.jcc.DB2Driver
看起来您还没有在maven依赖项中添加 db2jcc 。请通过查看依赖关系树来验证:
mvn dependency:tree -Dverbose
如果您的测试在IDE中正常运行。您可以在类路径中手动添加 db2jcc - * jar。
如果您已在maven依赖项中指定了依赖项并仍然收到错误,那么您的应用程序可能会占用大量内存,并且maven无法将所有类加载到已分配的堆中。 它可以通过增加内存来进行可靠性测试来解决。
为此,请参阅here提到的答案。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Xms$512m -Xmx$512m</argLine>
</configuration>
</plugin>