title: Not able to get spring service bean in Thread
body: <p>I have a Spring web application in which I have multiple Service and DAO classes. In normal crud operations everything is working fine. But I am facing issue while injecting dependency in thread.</p>
  
  <p>In my application I need to create a thread and execute it on demand. For this in a controller class I am creating thread like below.</p>
  
  <pre><code>TestThread testThread = new TestThread();
  Thread thread = new Thread(testThread);
  thread.start(); 
  </code></pre>
  
  <p>In my thread I am trying to get a dependency like below.</p>
  
  <pre><code>WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();        
  TestService testService = (TestService) context.getBean("myService");
  </code></pre>
  
  <p>My service class looks below.</p>
  
  <pre><code>@Service("myService")
  public class TestServiceImpl implements TestService {
      some methods...
  }
  </code></pre>
  
  <p>But every time I am getting below exception.</p>
  
  <pre><code>Exception in thread "Thread-21" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myService' available
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1199)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
  </code></pre>