1. 程式人生 > >No qualifying bean of type [com.it.service.DeptService] found for dependency

No qualifying bean of type [com.it.service.DeptService] found for dependency

今天出現了這樣一個錯誤,弄了好久,意思就是我的'deptEmpController沒有deptsv依賴,找了好半天,終於找到了原因。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptEmpController': Unsatisfied dependency expressed through field 'deptsv': No qualifying bean of type [com.it.service.DeptService] found for dependency [com.it.service.DeptService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. 

Spring管理service(通過xml讀取service,利用反射建立例項),controller的時候,由於Controller裡面注入了service,但實際並沒有找到service的例項化,慢慢找到原來在applicationContext-Service.xml中,沒有配置我所注入service,所以沒有辦法例項化,導致出錯

錯誤的配置(只配置了一個)

applicationContext-Service.xml:

 <bean id="empServiceImp" class="com.it.service.imp.EmpServiceImp"></bean>

正確的配置

applicationContext-Service.xml:

 <bean id="empServiceImp" class="com.it.service.imp.EmpServiceImp"></bean>

 <bean id="deptServiceImp" class="com.it.service.imp.DeptServiceImp"></bean>