admin管理员组

文章数量:1530085

使用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的多态 在使用中要尽量使用

本文标签: 报错异常原因方案SUN