Is there a way I can have S开发者_运维问答pring inject dependencies on construction of an object at runtime, rather than when parsing the Spring XML files or on package-scan?
I've got some objects that extend Thread and do file transfers. It be nice to have the services these Thread sublasses depend on autowired, so I don't have to pass them all in the constructor.
BONUS QUESTION!
Is there anything I need to do with these Thread subclasses once they've done their run() implementation has finished? Do they need 'killing' somehow?
I'd use the Spring injection facilities as is. You can inject a ThreadPoolTaskExecutor and let your objects use that. No Threads will be killed or harmed by your application: Spring will manage them all.
精彩评论