整合spring和mybatis的时候,进行测试报这个错。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java: 763 )
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java: 142 )
at java.net.URLClassLoader.defineClass(URLClassLoader.java: 467 )
at java.net.URLClassLoader.access$ 100 (URLClassLoader.java: 73 )
at java.net.URLClassLoader$ 1 .run(URLClassLoader.java: 368 )
at java.net.URLClassLoader$ 1 .run(URLClassLoader.java: 362 )
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java: 361 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 424 )
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java: 335 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 357 )
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java: 763 )
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java: 142 )
at java.net.URLClassLoader.defineClass(URLClassLoader.java: 467 )
at java.net.URLClassLoader.access$ 100 (URLClassLoader.java: 73 )
at java.net.URLClassLoader$ 1 .run(URLClassLoader.java: 368 )
at java.net.URLClassLoader$ 1 .run(URLClassLoader.java: 362 )
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java: 361 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 424 )
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java: 335 )
at java.lang.ClassLoader.loadClass(ClassLoader.java: 357 )
at org.mybatis.spring.mapper.ClassPathMapperScanner.<init>(ClassPathMapperScanner.java: 73 )
at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java: 308 )
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java: 119 )
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java: 693 )
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java: 531 )
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java: 144 )
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java: 85 )
at com.cat.test.SpringMybatis.test1(SpringMybatis.java: 18 )
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.junit.runners.model.FrameworkMethod$ 1 .runReflectiveCall(FrameworkMethod.java: 47 )
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java: 12 )
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java: 44 )
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java: 17 )
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java: 271 )
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java: 70 )
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java: 50 )
at org.junit.runners.ParentRunner$ 3 .run(ParentRunner.java: 238 )
at org.junit.runners.ParentRunner$ 1 .schedule(ParentRunner.java: 63 )
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java: 236 )
at org.junit.runners.ParentRunner.access$ 000 (ParentRunner.java: 53 )
at org.junit.runners.ParentRunner$ 2 .evaluate(ParentRunner.java: 229 )
at org.junit.runners.ParentRunner.run(ParentRunner.java: 309 )
at org.junit.runner.JUnitCore.run(JUnitCore.java: 160 )
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java: 69 )
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java: 33 )
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java: 220 )
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java: 53 )
|
主要是因为少了下面这个包,导入即可。
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.0.0.RELEASE</version> </dependency>
注意,版本一定要和你其他的spring包对应好。