在MyBatis案例中,我需要知道底层如何把传入参数存放到map中进行封装,所以sqlSession.getMapper()行处加了断点,正常在测试方法名处Debug运行…,不像往常提示需要导入确定的Jar名称信息,准备的说不是很明确,而是友好提示The source attachment does not contain the source for the file DelegatingMethodAccessorImpl.class。。。最终我找到了原因,需要导入本地安装的JDK下JRE中lib文件下的Jar文件!
Debug代码处:
!!!细节:测试类修饰最好是public,测试方法一定不要忘记注解@Test,Junit4和Junit5版本有区别,我使用的Junit4!
/*
* 测试传递多个参数
*/
public class TestMybatis_CRUD {
…
@Test
public void testSelectEmployeeByIdAndName2() {
EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); //======此处加上断点
//接口没有实现,是动态生成的
Employee employee=employeeMapper.selectEmployeeByIdAndName2(1, “林大侠”);
System.out.println(employee);
}
}
’
窗口提示信息:
// (version 1.8 : 52.0, super bit)
class sun.reflect.DelegatingMethodAccessorImpl extends sun.reflect.MethodAccessorImpl {
// Field descriptor #17 Lsun/reflect/MethodAccessorImpl;
private sun.reflect.MethodAccessorImpl delegate;
// Method descriptor #18 (Lsun/reflect/MethodAccessorImpl;)V
// Stack: 2, Locals: 2
DelegatingMethodAccessorImpl(sun.reflect.MethodAccessorImpl arg0);
0 aload_0 [this]
1 invokespecial sun.reflect.MethodAccessorImpl() [25]
4 aload_0 [this]
5 aload_1 [arg0]
6 invokevirtual sun.reflect.DelegatingMethodAccessorImpl.setDelegate(sun.reflect.MethodAccessorImpl) : void [24]
9 return
// Method descriptor #2 (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
// Stack: 3, Locals: 3
public java.lang.Object invoke(java.lang.Object arg0, java.lang.Object[] arg1) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException;
0 aload_0 [this]
1 getfield sun.reflect.DelegatingMethodAccessorImpl.delegate : sun.reflect.MethodAccessorImpl [23]
4 aload_1 [arg0]
5 aload_2 [arg1]
6 invokevirtual sun.reflect.MethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[]) : java.lang.Object [26]
9 areturn
// Method descriptor #18 (Lsun/reflect/MethodAccessorImpl;)V
// Stack: 2, Locals: 2
void setDelegate(sun.reflect.MethodAccessorImpl arg0);
0 aload_0 [this]
1 aload_1 [arg0]
2 putfield sun.reflect.DelegatingMethodAccessorImpl.delegate : sun.reflect.MethodAccessorImpl [23]
5 return
}
第一步:点击change Attached Source

第二步:点击change Attached Source

第三步:找到jre下lib包中的rt.jar,选中

第四步:回到第二步,点击ok按钮即可
注意:先退出此页面,刚引入Jar,不会直接进入源文件,重新debug操作即可!

最后,我对rt.jar进行反编译,进行了验证!

☝上述分享来源个人总结,如果分享对您有帮忙,希望您积极转载;如果您有不同的见解,希望您积极留言,让我们一起探讨,您的鼓励将是我前进道路上一份助力,非常感谢!我会不定时更新相关技术动态,同时我也会不断完善自己,提升技术,希望与君同成长同进步!
☞本人博客:https://coding0110lin.blog.youkuaiyun.com/ 欢迎转载,一起技术交流吧!
本文详细记录了解决在使用MyBatis进行Debug时遇到的源码加载问题,包括如何正确设置测试类和方法,以及如何导入本地JDK下的rt.jar文件来解决DelegatingMethodAccessorImpl.class源码缺失的问题。

被折叠的 条评论
为什么被折叠?



