title: Adding Jackson to POM causes NoClassDefError for JsonProcessingException
body: <p>First off, I apologize for bringing this question up again. The last time was 3 months ago, and I found a stopgap method that kind of worked back then for the proof of concept. Unfortunately, I really need to get this working properly for the full </p>
  
  <p>As part of my current project, I need to be able to serialize objects automatically to and from JSON as requests are sent to and from a Spring server. I've been told to use Jackson for this. The problem is, every time I add Jackson to the POM it will build, but the servlet throws a java.lang.NoClassDefError when it can't find com.fasterxml.jackson.core.JsonProcessingException. I've  checked though, JsonProcessingException is where it should be expected in the WAR.</p>
  
  <p>My suspicion is that the  is causing Spring to try to autowire a Jackson parser for the servlet and it's unable to find all of the dependencies. I have no idea why this is though, as they <em>should</em> be getting pulled in properly by Maven.</p>
  
  <p>My pom.xml with company specifics generalized:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;com.company.department&lt;/groupId&gt;
          &lt;artifactId&gt;project&lt;/artifactId&gt;
          &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;artifactId&gt;project-restservice&lt;/artifactId&gt;
  
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;projectMaven Restservice&lt;/name&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
              &lt;artifactId&gt;project-common&lt;/artifactId&gt;
              &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
              &lt;artifactId&gt;project-processor&lt;/artifactId&gt;
              &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
              &lt;artifactId&gt;project-ui-service&lt;/artifactId&gt;
              &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.qualcomm.qes.logging&lt;/groupId&gt;
              &lt;artifactId&gt;project-logger&lt;/artifactId&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;org.slf4j&lt;/artifactId&gt;
                      &lt;groupId&gt;com.springsource.slf4j.api&lt;/groupId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;org.slf4j&lt;/artifactId&gt;
                      &lt;groupId&gt;com.springsource.slf4j.log4j&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;commons-logging&lt;/groupId&gt;
              &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.qualcomm.qes.sso.downstream&lt;/groupId&gt;
              &lt;artifactId&gt;sso-downstream-auth&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;bcprov-jdk15on&lt;/artifactId&gt;
                      &lt;groupId&gt;bouncycastle&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;!-- SpringSource --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.web.servlet&lt;/artifactId&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.core&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.beans&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.context&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.oxm&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
                      &lt;groupId&gt;xml-apis&lt;/groupId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;!-- Other --&gt;
  
  
          &lt;!-- Jackson JSON Mapper --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;2.5.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- JMS --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
              &lt;artifactId&gt;com.springsource.javax.transaction&lt;/artifactId&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;com.springsource.javax.servlet&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- TIBCO JMS --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.tibco&lt;/groupId&gt;
              &lt;artifactId&gt;tibjms&lt;/artifactId&gt;
  
          &lt;/dependency&gt;
  
          &lt;!-- TESTS --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;org.springframework.test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;${project.artifactId}-${project.version}&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;!-- TODO: wants version number --&gt;
                  &lt;configuration&gt;
                      &lt;webResources&gt;
                          &lt;resource&gt;
                              &lt;directory&gt;${basedir}/src/main/webapp/WEB-INF&lt;/directory&gt;
                              &lt;filtering&gt;true&lt;/filtering&gt;
                              &lt;targetPath&gt;WEB-INF&lt;/targetPath&gt;
                              &lt;includes&gt;
                                  &lt;include&gt;**/jboss-classloading.xml&lt;/include&gt;
                              &lt;/includes&gt;
                          &lt;/resource&gt;
                      &lt;/webResources&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;deploy-war&lt;/id&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;deploy-to-server&lt;/id&gt;
                                  &lt;phase&gt;install&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;run&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;tasks&gt;
                                          &lt;copy file="${project.build.directory}/${project.artifactId}-${project.version}.war" todir="${project.jboss.home}/standalone/deployments/project.ear/"&gt;&lt;/copy&gt;
                                      &lt;/tasks&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
  
  
      &lt;/profiles&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>My web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/project-restservice-servlet.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;project-restservice&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;project-restservice&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My servlet context:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:oxm="http://www.springframework.org/schema/oxm"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                  http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
                  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="com.company.department.project.controller" /&gt;
  
      &lt;mvc:annotation-driven/&gt;
  
      &lt;mvc:resources mapping="/html/**" location="/static/html/" /&gt;
      &lt;mvc:resources mapping="/js/**" location="/static/js/" /&gt;
      &lt;mvc:resources mapping="/css/**" location="/static/css/" /&gt;
      &lt;mvc:resources mapping="/images/**" location="/static/images/" /&gt;
  
  
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;     
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>My controller:</p>
  
  <pre><code>@Controller
  public class RestServiceWebController extends BaseRestServiceController
  {
  
     @Autowired
     private SampletableService sampletableService;
  
     @RequestMapping(value="/sample", method=RequestMethod.GET)
     public String customerPortal(ModelMap model)
     {
       return "sample";
     }
  
    @RequestMapping(value="/testService", method=RequestMethod.GET)
    public @ResponseBody Map&lt;String, String&gt; testMethod()
    {
      logger.info("In testService");
      Map&lt;String,String&gt; testResponse = new HashMap&lt;String, String&gt;();
      testResponse.put("1", "2");
      testResponse.put("3", "4");
      testResponse.put("5", "6");
      testResponse.put("7", "8");
      testResponse.put("9", "0");
      return testResponse;
    }
  }
  </code></pre>
  
  <p>Excerpt from the log:</p>
  
  <pre><code>2015-02-19 09:35:56,638 ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 54) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
      at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:3777)
      at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)
      at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60)
      at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
      at org.jboss.threads.JBossThread.run(JBossThread.java:122)
  Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
      at java.lang.Class.getDeclaredConstructors(Class.java:1901)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:230)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:972)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:945)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      ... 22 more
  </code></pre>
  
  <p>Please let me know if you need any more information.</p>
  
  <p>Edit:</p>
  
  <p>So a little bit of probing and following similar threads, and I managed to trace it to the  tag which is autowiring the Jackson bean. Removing that and manually adding a converter like so: </p>
  
  <pre><code>&lt;bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /&gt;
  </code></pre>
  
  <p>Results in the same error. So at least now I know what's causing it, but the dependencies <em>are</em> there so I'm not sure why it's saying it can't find them.</p>