Exception in thread "main" org.s

2018-01-12  本文已影响0人  毛仑上保罗先生

如题, 我在一个普通的java项目中新建了一个bean.xml, 想通过spring的ioc去获取对象 ,谁知道出现这种错误,尝试过几种解决办法:

classpath*:bean.xml

   ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:bean.xml");
        UserImpl  userImpl =(UserImpl)applicationContext.getBean("userImpl");

这种方式在applicationContext.getBean("userImpl");会出现Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userImpl' available

根据项目结构目录一级一级的往下找(解决问题)

QQ截图20180112141429.png
  ApplicationContext applicationContext = new ClassPathXmlApplicationContext("cn/paul/bean.xml");
        UserImpl  userImpl =(UserImpl)applicationContext.getBean("userImpl");
        String name= userImpl.getName("paul");
        System.out.println(name);
上一篇下一篇

猜你喜欢

热点阅读