Dependency injection in Spring MVC? -


i trying use dependency injection in spring mvc web application. have function in controller

@requestmapping(value = "/stockgoogle/", method = requestmethod.get) public @responsebody stock stockgoogle(locale locale, model model) {         stockdaoimpl si = new stockdaoimpl();     //al=s.listcurrent(id);     stock s=si.listgoogle();     system.out.println("reached here");     model.addattribute("s", s );             return s; } 

i want dependency inject stockdaoimpl. can please tell me how can this. have been trying read of explainations complex. should use @autowired ? should put it? can please help.

you can inject through controller's constructor

class yourcontroller{    private final stockdao dao;    @autowired    public yourcontroller(stockdao dao){     this.dao = dao;   } }  

and stockdaoimpl has defined bean of course,

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

another way doing defining stockdaoimpl component


Comments

  1. Best free 1xbet - 2xbet and Login 1xbet in 1xBET
    This is a platform that provides grade 23 titanium 1xbet and 2xbet bet. We offer the best free 1xbet and 2xbet betting apple watch 6 titanium sites, for only players snow peak titanium from all over 1xbet app the world. Rating: 4.3 · ‎9 blue titanium votes

    ReplyDelete

Post a Comment

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? -