欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
    }
}

Bean named ‘Target‘ is expected to be of type ‘com.itheima.aop.Target‘ but was actually of type ‘com