2013-03-19 113 views
0

我試圖讓我的Android應用程序與我的服務器進行通信,該服務器託管着我的Web應用程序。對於Web方面,我使用Spring並且一切正常。我可以發送數據使用春天等數據庫。但現在,我試圖讓我的android應用程序與服務器通信。爲此,我遵循本教程:http://blog.trifork.com/2011/02/07/creating-an-android-app-for-your-website-with-spring-android-and-rest/創建ContentNegotiatingViewResolver時的BeanCreationException

現在,當我嘗試打開一個網頁時,我收到了很多例外。 (我甚至不需要嘗試從Android應用發送任何東西!)。它正常工作,直到我在我的springmvc-servlet.xml中編寫一些代碼爲止,因爲我是Spring的新手,所以在解決這些異常時遇到了麻煩。這是我的sprinmvc-servlet.xml的代碼(我改變了代碼的某些部分,跟隨他人的教程,但是當我使用的代碼我使用的第一個教程中,我得到了同樣的例外)

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    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"> 

    <context:component-scan base-package="com.puccamp.projetofinal" /> 
    <mvc:annotation-driven /> 
    <mvc:default-servlet-handler /> 

    <bean 
     class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
     <property name="mediaTypes"> 
      <map> 
       <entry key="html" value="text/html" /> 
       <entry key="json" value="application/json" /> 
      </map> 
     </property> 
     <property name="viewResolvers"> 
      <list> 
       <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> 
       <bean 
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
        <property name="prefix" value="/WEB-INF/views/" /> 
        <property name="suffix" value=".jsp" /> 
       </bean> 
      </list> 
     </property> 
     <property name="defaultViews"> 
      <list> 
       <bean 
        class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> 
      </list> 
     </property> 
    </bean> 

</beans> 

和這裏的異常(有很多的,但是不要害怕!d):

exception 

javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 
root cause 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Cannot create inner bean 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#129acbd' of type [org.springframework.web.servlet.view.json.MappingJacksonJsonView] while setting bean property 'defaultViews' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#129acbd' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.view.json.MappingJacksonJsonView]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) 
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) 
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) 
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) 
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
    javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 
root cause 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#129acbd' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.view.json.MappingJacksonJsonView]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) 
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) 
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) 
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) 
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
    javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 
root cause 

org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.view.json.MappingJacksonJsonView]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper 
    org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) 
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) 
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) 
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) 
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) 
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
    javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 
root cause 

java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper 
    org.springframework.web.servlet.view.json.MappingJacksonJsonView.<init>(MappingJacksonJsonView.java:56) 
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    java.lang.reflect.Constructor.newInstance(Unknown Source) 
    org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) 
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) 
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) 
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) 
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) 
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) 
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) 
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) 
    javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) 
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    java.lang.Thread.run(Unknown Source) 

回答

1

我一直在尋找的答案你的問題,我在StackOverflow上

java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper on Spring 3 project

這裏發現這個職位

也許該帖子的解決方案與您的問題有關。

所以可能Jackson在classpath中失蹤

+0

我已經看到了這個問題,以及..我下載了它,但它仍然沒有工作。我應該下載傑克遜核心,傑克遜的註解和傑克遜,數據綁定?我剛剛下載了核心版本 – 2013-03-19 21:02:22

+0

我下載了所有這些文件..但沒有做任何事情 – 2013-03-19 21:09:46

+0

我更改了版本os jackson for 1.1.0,它的工作原理!謝謝 – 2013-03-20 14:06:13

相關問題