Spring学习——org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘emp‘ is expe

    @Test
    public void Test4(){
    
    
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean6.xml");
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
    }
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'emp' is expected to be of type 'com.atguigu.spring5.bean.Emp' but was actually of type 'com.atguigu.spring5.autowire.Emp'

意思是,我们导错了包:
可以看到

import com.atguigu.spring5.bean.Emp;
import com.atguigu.spring5.bean.Orders;

在这里插入图片描述
只需要在开头修改导入的包即可:

import com.atguigu.spring5.autowire.Emp;

Supongo que te gusta

Origin blog.csdn.net/d347091231/article/details/120745684
Recomendado
Clasificación