java - Spring autowired user -


i have authentication service, , module clients, can included retrieve authenticated user , verify token.

what want achieve able this: @autowired myuser user retrieve correct user (request scope).

what i've done:

in separate module clients can include:

@configuration public class myuserholder {     @bean     @scope(value="request", proxymode= scopedproxymode.target_class)     public myuser getmyuser() {         return (myuser) securitycontextholder.getcontext().getauthentication().getprincipal();     } } 

and in client:

@autowired myuser user 

there no annotations on myuser class (is correct?)

the error is:

org.springframework.beans.factory.nosuchbeandefinitionexception:  no qualifying bean of type [...myuser] found dependency [...myuser]: expected @ least 1 bean qualifies autowire candidate dependency.  

i'm not sure if problem comes fact object , annotations in module (included jar), or if annotations incomplete... feels myuserholder not correctly available in spring-context

generally issue occurs when spring can't find bean autowire, means before autowiring, respective bean needs created. making sure application scanning (component scan) myuserholder class before auto-wiring myuser in client resolve such issues.


Comments