Accessing Spring beans in Runnable thread
<p>I need to access Spring beans(<code>featureService</code> and <code>uxService</code>) in my Runnable Thread below but am getting <code>null</code> value for <code>applicationContext</code> hence I couldnt get Spring beans inside the Runnable. I am wondering if its possible to access spring beans inside a runnable or not? if not please suggest me an alternative approach.</p>

<p>I am using <code>Spring 4.0.6</code> and <code>Java 8</code></p>

<pre><code>@Component
public class UserMenuUpdateTask implements Runnable, Serializable, ApplicationContextAware {


    private static final long    serialVersionUID = 3336518785505658027L;

    List&lt;User&gt;                   userNamesList;

    FeatureService               featureService;

    UXService uxService;

    private ApplicationContext   applicationContext;

    public UserMegaMenuUpdateTask() {}

    public UserMegaMenuUpdateTask(List&lt;User&gt; userNamesList) {
        this.userNamesList = userNamesList;
    }

    @Override
    public void run() {
        try {
            for (User user : userNamesList) {

                    featureService = (FeatureService) applicationContext.getBean("featureService");
                    uxService = (UxService) applicationContext.getBean("uxService");                    
                //.........
            }
        } catch (BaseApplicationException ex) {
            throw new BaseApplicationException(ex);
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;

    }
}
</code></pre>

<p>I am calling the runnable as below </p>

<pre><code>ExecutorService es = Executors.newCachedThreadPool();
es.execute(new UserMenuUpdateTask(activeUsers));
</code></pre>