找不到bean NoSuchBeanDefinitionException

时间:2019-07-04 21:13:01

标签: java spring javabeans

我尝试通过使用ClassPathXmlApplicationContext获得bean。但我收到:NoSuchBeanDefinitionException: No bean named 'newsController' is defined

ApplicationContext applicationContext = new 
ClassPathXmlApplicationContext("classpath*:conf/Spring_Config.xml");

NewsController newsController = (NewsController) 
applicationContext.getBean("newsController");

xml 中:

  <bean id="newsController" class="NewsController"/>

1 个答案:

答案 0 :(得分:0)

为bean类标记添加完整路径

class = com.foo.NewsController