异常报错:but was actually of type [com.sun.proxy.$Proxy11]处理方案及原因

编程入门 行业动态 更新时间:2024-10-26 19:41:07

使用ssh编写项目常用@resource进行自动装配
但是偶尔使用不当对报一些小错误
but was actually of type [com.sun.proxy.$Proxy11]
这个问题是jdk代理报错
jdk代理需要实现接口才能实现代理 所以我们使用的resource自动注入的属性需要用接口来承接

@Resource
	private StudentService studentservice;
	
	@Test
	public void testApp() throws Exception {
		Student stu = new Student();
		stu.setName("小花");
		stu.setPhonenum("15644561215");
		stu.setStuid("16020440323");
		stu.setDormnum("A6-505");
		studentservice.save(stu);
		
	}

上面的代码会报错 而使用接口的就不会

@Resource
	private IStudentService studentservice;
	
	@Test
	public void testApp() throws Exception {
		Student stu = new Student();
		stu.setName("小花");
		stu.setPhonenum("15644561215");
		stu.setStuid("16020440323");
		stu.setDormnum("A6-505");
		studentservice.save(stu);
		
	}

使用接口来接受对象体现了java的多态 在使用中要尽量使用

更多推荐

异常报错:but was actually of type [com.sun.proxy.$Proxy11]处理方案及原因

本文发布于:2023-06-13 16:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   异常   原因   方案   sun

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!