I'm having trouble getting @Autowired to work in a class annotated with @Service, the variable is automatically set to zero. Let me explain:
@Service
public class Searcher extends Thread implements ISearcher {
@Autowired
protected ISessionProvider sessionProvider; <-- always null
...
public Searcher() {
sessionProvider.doSomeStuff();
}
sessionProvider is always null here.
The strange thing is that the same auto-host in @Controller works:
@Controller
@RequestMapping("/search")
@Secured({ "ROLE_USER" })
public class SearchController extends BaseController {
@Autowired
protected ISessionProvider sessionProvider; <-- does work
@Autowired
protected ISearcher searcher;
The last line throws an exception because the Searcher constructor (implementing ISearcher) tries to access sessionProvider, which is null.
I'm not sure what I can do wrong, it looks like spring is not an autowire ISessionProvider in Searcher.
, spring Searcher SearchController, SessionProvider Searcher Searcher SearchController. , SessionProvider. ; -)
- ?
[]
- - , , .
- ( )
- , "" , , "", spring , .