org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name已解決!

org.springframework.beans.factory.UnsatisfiedDependencyException

今天搭環境的時候遇到這個錯,浪費了我好久,類似下面這種錯誤
Error creating bean with name 'userController'
Error creating bean with name 'userService'
No qualifying bean of type 'xyz.nandu.dao.UserDao' available
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userService’: Unsatisfied dependency expressed through field ‘userDao’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘xyz.nandu.dao.UserDao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

網上方法很多,我看了半天,註解啊什麼都沒有問題,發現沒有加監聽器
解決方法:

  1. 檢查對應的註解,確定都沒有問題
  2. 檢查web.xml裏有沒有加spring的監聽器
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 設置配置文件的路徑-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>

加上試試,希望可以幫到大家!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章