Spring学习-org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘myBean‘ ava

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘myBean’ available

意思是:没有名为“myBean”的bean可用

代码:

    @Test
    public void Test4(){
    
    
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean6.xml");
        Emp emp = context.getBean("myBean", Emp.class);
        System.out.println(emp);
    }

在这里插入图片描述
更改后:

    @Test
    public void Test4(){
    
    
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean6.xml");
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
    }

正确输出

おすすめ

転載: blog.csdn.net/d347091231/article/details/120745350