![](/img/trans.png)
[英]Spring can't find bean and throws NoSuchBeanDefinitionException
[英]Did not find bean NoSuchBeanDefinitionException
我嘗試通過使用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"/>
將完整路徑添加到bean類標簽
class = com.foo.NewsController
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.