title: Spring @Component HttpGet execute
body: <p>I have a Spring MVC application. The problem is that I can't execute HttpGet and receive response inside @Component class. Here is what my @Component class function looks like:</p>
  
  <pre><code>private String getSite(String url) throws IOException, InterruptedException {
      HttpClient httpclient = HttpClients.createDefault();
      HttpGet httpget = new HttpGet(url);
      HttpResponse response = httpclient.execute(httpget); // This line causes the problem
  
      BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
      StringBuilder builder = new StringBuilder();
      for (String line = null; (line = reader.readLine()) != null; ) {
          builder.append(line).append("\n");
      }
      return builder.toString(); 
  }
  </code></pre>
  
  <p>The thing is that in works in console app perfectly fine.
  Here is my maven pom.xml(included httpComponents):</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
              &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
              &lt;version&gt;4.3.5&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is the error message I receive when web app is deployed and the first page is loaded:</p>
  
  <pre><code>&gt; HTTP Status 500 - Servlet.init() for servlet mvc-dispatcher threw
  &gt; exception
  type Exception report
  message Servlet.init() for servlet mvc-dispatcher threw exception
  description The server encountered an internal error that prevented it from fulfilling this request.
  exception javax.servlet.ServletException: Servlet.init() for servlet mvc-dispatcher threw exception
  
  root cause java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
  root cause java.lang.ClassNotFoundException: org.apache.http.HttpEntity
  
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
      java.lang.Class.getDeclaredConstructors0(Native Method)
      java.lang.Class.privateGetDeclaredConstructors(Class.java:2532)
      java.lang.Class.getDeclaredConstructors(Class.java:1901)
  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:230)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:976)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
  org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
  org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
  org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
  org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
  org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
  org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>