美文网首页
Exception in thread "main" org.s

Exception in thread "main" org.s

作者: 毛仑上保罗先生 | 来源:发表于2018-01-12 14:15 被阅读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);

相关文章

网友评论

      本文标题:Exception in thread "main" org.s

      本文链接:https://www.haomeiwen.com/subject/eslfoxtx.html