2017-04-21 59 views
0

平台:Eclipse的霓虹+用SpringMVC + JPA +行家 springframework的4.3 当我使用JUnit测试,代码是好的,控制台显示正确结果,控制台秀细节:使用JUnit测试是确定的,但使用Maven测试也不行,

19:01:43.491 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]71c8becc, org.springframework.test[email protected]19d37183, org.springframewor[email protected]1a0dcaa, org.springfra[email protected]3bd40a57, org.springframew[email protected]fdefd3f, org.sp[email protected]d83da2e] 
19:01:43.504 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]78e94dcf, org.springframework.test[email protected]233fe9b6, org.springframewor[email protected]358ee631, org.springfra[email protected]ec756bd, org.springframew[email protected]3c72f59f, org.sp[email protected]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 [email protected]aaecc3: 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 [[email protected] testClass = TdFinaacctMainDaoTest, testInstance = [email protected]bd8, testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [[email protected]]; rollback [true] 
19:01:51.147 [main] INFO o.s.t.c.t.TransactionContext - Rolled back transaction for test context [[email protected] testClass = TdFinaacctMainDaoTest, testInstance = [email protected]bd8, testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [[email protected] testClass = JpaMappingTest, testInstance = [email protected], testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [[email protected]]; 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 [[email protected] testClass = JpaMappingTest, testInstance = [email protected], testMethod = [email protected], testException = [null], mergedContextConfiguration = [[email protected] 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 [email protected]aaecc3: 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测试,控制台显示这些错误:抛出java.lang.ClassNotFoundException:

[INFO] ------------------------------------------------------- 
[INFO] T E S T S 
[INFO] ------------------------------------------------------- 
19:03:22.107 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]31368b99, org.springframework.test[email protected]1725dc0f, org.springframewor[email protected]3911c2a7, org.springfra[email protected]4ac3c60d, org.springframew[email protected]4facf68f, org.sp[email protected]76508ed1] 
19:03:22.115 [main] INFO o.s.t.c.s.DefaultTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]7714e963, org.springframework.test[email protected]20ce78ec, org.springframewor[email protected]393671df, org.springfra[email protected]56620197, org.springframew[email protected]6eda5c9, org.sp[email protected]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 [email protected]bc55de: 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.springframewor[email protected]3911c2a7] to prepare test instance [[email protected]] 
[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 [email protected]27a7e: 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.springframewor[email protected]393671df] to prepare test instance [[email protected]f02] 
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

所致com.ibm.db2.jcc.DB2Driver

看起来像你还没有添加db2jcc在你的maven依赖项中。请通过查看依赖关系树来验证:

mvn dependency:tree -Dverbose 

如果您的测试在IDE中正确运行。您可能已在您的类路径中手动添加了db2jcc- * jar。


如果指定的依赖在你的Maven的依赖,仍然出现错误,则有可能是您的应用程序对内存重和Maven是不能所有的类加载到分配的堆。 它可以通过增加记忆为surefire测试解决。

有关详情,请参阅提及的答案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>