title: Spring HtmlUnit dependency
body: <p>I have a Spring MVC application with HtmlUnit dependencies. I am using HtmlUnit utilities inside @Component class. The problem is that after compilation(<strong>root cause java.lang.NoClassDefFoundError: org/apache/http/HttpEntity</strong>), on browser start up (index page), I see the page with:</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>
  
  <p>All dependencies needed I have included using maven, here is my <strong>pom.xml</strong>:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;net.sourceforge.htmlunit&lt;/groupId&gt;
      &lt;artifactId&gt;htmlunit&lt;/artifactId&gt;
      &lt;version&gt;2.15&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
      &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
      &lt;version&gt;3.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
      &lt;version&gt;4.3.5&lt;/version&gt;
  &lt;/dependency&gt;
  &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><em>If I remove @Component annotation from class - the application doesn't fail on start up</em>, but on actual controller call, which uses the class(with HtmlUnit inside) - same error. If I remove class that uses HtmlUnit from controller, everything works great. <em>I also tried adding libraries by myself</em>, without using maven - didn't help ether. <strong>The main mystery about it, is that my class(that uses HtmlUnit) perfectly works in usual console application.</strong> So I tried many things, and I still don't get what is the reason of this problem, why it doesn't work on Spring??? Maybe HtmlUnit is only meant for one threaded applications? But why there is ClassNotFoundException?</p>