java - No matching bean of type found for dependency: Spring MVC -


i getting error when trying use @autowire, @configuration, @bean, @repository in spring mvc project

could not autowire field: private com.sachin.dao.stockdaoimpl com.sachin.myapp.homecontroller.stockdao;

nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no matching bean of type [com.sachin.dao.stockdaoimpl] found dependency:

please let me know mistake making. new spring mvc , dependency injection.

here controller code. trying inject stockdaoimpl in controller.

@controller public class homecontroller {       @autowired     private stockdaoimpl stockdao;      @requestmapping(value = "/stockgoogle/", method = requestmethod.get)     public @responsebody stock stockgoogle(locale locale, model model) {             //stockdaoimpl stockdao = new stockdaoimpl();         stock s=stockdao.listgoogle();         model.addattribute("s", s );                 return s;     }  } 

my service implementation below. have used @repository annotation here "stockdao" variable name in controller want inject

@repository("stockdao") public class stockdaoimpl implements stockdao {      @override     public stock listgoogle() {         stock s = null;         try {             ... //some code             string  name = rs.getstring("name");             s = new stock(name);             ...          } catch (exception e) {          }          return s;     } } 

also have created configuration class separately. using define bean. using specify bean , have not imported anywhere in code.

@configuration public class beanconfiguration {     @bean     public stockdaoimpl stockdao(){       return new stockdaoimpl();     } } 

am missing here. looking @ error looks @bean annotation not visible factory. have else other annotating @configuration class.

i might using annotations in wrong way. making mistake in how using @autowired or @repository.

can please help.

i think might issue:

"also have created configuration class separately. using define bean. using specify bean , have not imported anywhere in code."

somewhere need tell spring beanconfiguration. can in applicationcontext.xml file (assuming have one) follows:

<context:component-scan base-package="com.sachin.config" /> 

this assumes beanconfiguration in com.sachin.config package.

if can't find put may helpful share web.xml file.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -