关于org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'heroService' is

来源:互联网 发布:宝信软件股份有限公司 编辑:程序博客网 时间:2024/06/04 18:24

出现这个异常的原因是因为在spring的上下文中找不到相应bean类。

如果你的xml配置和注解都没有什么问题,那么就看你在解析xml文件的时候按如:


@Test
 public void test(){

加载xml
  BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext.xml");

////////////////////////////////////////////////////////////////////////注意这里是相应接口的实例
  HeroService hd = (HeroService) bf.getBean("heroServiceImpl");
  System.out.println(hd.query());
 }

这样依赖就不会报org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'heroService' is了,一个是因为在spring的上下文中找不到相应bean类

阅读全文
0 0