spring - How to autowire a service and a repository together -


i have fix following error. can help

severe: standardwrapper.throwable org.springframework.beans.factory.beancreationexception: error creating bean name 'searchcontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire method: public void com.website.dev.controller.searchcontroller.setrecordingservice(com.website.dev.service.recordingservice); nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.website.dev.service.recordingservice] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}

@controller public class searchcontroller {      private recordingservice recordingservice;      @autowired     public void setrecordingservice(recordingservice recordingservice) {         this.recordingservice = recordingservice;     }      @requestmapping("/search")     public string showsearch(){         return "search";     } }  @service("recordingservice") public interface recordingservice  {      //methods }   public class recordingserviceimpl implements recordingservice  {      @autowired     private recordingrepository recordingrepository;      //methods use recordingrepository }  public interface recordingrepository {   }  @repository public class recordingjparepository implements recordingrepository {      @persistencecontext     private entitymanager entitymanager;     //methods use entitymanager } 

service-context.xml

<context:annotation-config></context:annotation-config>         <context:component-scan            base-package="com.website.dev.service">         </context:component-scan> </beans> 

website-servlet.xml

<context:component-scan      base-package="com.website.dev.controller"> // searchcontroller in package </context:component-scan> 

web.xml

<context:component-scan      base-package="com.enepath.dev.controller"> </context:component-scan> 

edit

if autowire recordingserviceimpl following

org.springframework.beans.factory.beancreationexception: error creating bean name 'recordingserviceimpl': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private com.website.dev.repository.recordingrepository com.website.dev.service.recordingserviceimpl.recordingrepository; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.website.dev.repository.recordingrepository] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)}

i added following configuration in service-context.xml , solved issue

   <context:annotation-config></context:annotation-config>    <context:component-scan         base-package="com.website.dev.service">     </context:component-scan>     <context:component-scan          base-package="com.website.dev.repository">     </context:component-scan>     <context:component-scan          base-package="com.website.dev.repository.jpa">     </context:component-scan> 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -