spring mvc - @Autowired field is null in one SpringMVC controller while others work -


i've quite simple , classic page spring mvc controller , jsp (the jsp not relevant here):

@controller public class playlistlistcontroller  extends basecontroller<playlist> {      @autowired userrepository userrepository;      @requestmapping("/playlist/{username}")     private modelandview displaylist(@pathvariable("username") string username) {         user user = userrepository.getuserbyusername(username);         ....     }  } 

my problem following. when want access page url: http://localhost:8080/playlist/foo throws nullpointeurexception in controller @ line 8.

    user user = userrepository.getuserbyusername(username); 

when debugging, see userrepository indeed null.

userrepository supposed injected spring, , in other controllers, happens fine: same bean (userrepository) correctly injected sptring.

why in specific controller (which in same package others) instantiated , called spring, userrepository null? don't understand @ all. suggestion welcome.

thanks! emile.

i found answer when proceed way: created @postconstruct method in controler see if userrepository injected @ beginning. indeed, when @postconstruct method running, userrepository not null. while debugging methodi found id of object ( in view variable on eclipse ) 307. besides, when debugging displaylist method, "this" shown proxy. so, looks @postconstruct method test () running in bean whime @requestmapping displaylist method running in proxy. in proxy, userrepository null.

so why @requestmapping displaylist () running in proxy ? reason method private. if turn displaylist() public method, works fine.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -