Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误

Caused by: java.lang.IllegalArgumentException

详细错误信息:

===========================================================================================================================================
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [E:\workspace\spring_mybatis\bin\cn\gts\ssm\mapper\UserMapper.class]; nested exception is java.lang.IllegalArgumentException
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.mybatis.spring.mapper.ClassPathMapperScanner.doScan(ClassPathMapperScanner.java:155)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.scan(ClassPathBeanDefinitionScanner.java:220)
at org.mybatis.spring.mapper.MapperScannerConfigurer.postProcessBeanDefinitionRegistry(MapperScannerConfigurer.java:315)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at cn.gts.ssm.test.UserMapperTest.testFindUserById(UserMapperTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
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:675)
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: java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.asm.ClassReader.(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:52)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
... 32 more
==========================================================================================================================================

原因分析:

    可以看到主要的错误信息是Caused by: java.lang.IllegalArgumentException,最后这个单词的意思是“非法的数据异常”,主要原因是由于jdk版本和spring的相关jar包的版本有冲突,也就是,spring的版本过低和jdk8的版本会出现这个问题。
解决方案:
    我原来采用的是spring3.2.0的版本jdk8.0的版本,就出现了这个问题,然后我把spring的所有jar包都升级到了4.2.4的版本,然后测试正常。

相关jar包下载:     

spring:http://maven.springframework.org/release/org/springframework/spring/

下载流程:

    1.打开上述链接得到如下页面
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第1张图片
 2.向下滑动找到要下载的版本点进去(以4.2.4为例)
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第2张图片

3.得到如下
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第3张图片
我们只需要下载第一个zip就好。
4.解压后找到libs文件夹下找到所有的jar包(不需要全部复制,用哪个选哪个就好)
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第4张图片

最后

    把所要的相关jar包复制到你的项目中然后后替换掉原来的版本就好了!
  还有一点,当你替换下已经build path的jar后,在下一次启动eclipse后,会在那个项目前面出现红色感叹号,主要是有由于项目中还记录着原来版本的jar包,但是实际上已经不存在了。

Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第5张图片

解决方案

    **选中改项目,鼠标右键,在右键菜单中,依次找到:Build Path config build path或者Build Path configure build path。
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第6张图片
    **会在下图出现许多spring3.2版本的jar包记录,而且带有红色叹号,将这些全部remove即可。(下图已经修改)
Spring+Mybatis整合时Caused by: java.lang.IllegalArgumentException错误_第7张图片

    这样就大功告成了!













你可能感兴趣的:(Spring,JavaEE,mybatis)