Bean named ‘Target‘ is expected to be of type ‘com.itheima.aop.Target‘ but was actually of type ‘com
程序员文章站
2022-04-30 13:58:34
...
这是一个接口实现方法
package com.itheima.aop;
public class Target implements TargetInterface{
public void save() {
System.out.println("save running.....");
}
}
这是定义的接口
package com.itheima.aop;
public interface TargetInterface {
public void save();
}
用Spring集合junit进行测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class AopTest {
@Autowired
private Target target;
@Test
public void test1() {
target.save();
}
}
报错如下:
Bean named ‘Target’ is expected to be of type ‘com.itheima.aop.Target’ but was actually of type 'com
修改代码,把target定义为TargetInterface,不报错:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class AopTest {
@Autowired
private TargetInterface target;
@Test
public void test1() {
target.save();
}
}
下一篇: Linux组管理与权限管理