2012-06-20 29 views
2

我試圖設置一個沒有Maven的Spring項目。我的項目必須通過Spring MVC框架提供jsp頁面和json流。 jsp頁面部分工作得很好,但是當我嘗試建立JSON流(爲了使AJAX所得到的),我得到java.lang.ClassNotFoundException:Spring 3上的org.codehaus.jackson.map.ObjectMapper項目

java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper 

我servletname-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:p="http://www.springframework.org/schema/p" 
xmlns:context="http://www.springframework.org/schema/context" 
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/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    "> 
<mvc:annotation-driven /> 
<context:component-scan base-package="org.package.servletname" /> 

<bean 
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
    <property name="mediaTypes"> 
     <map> 
      <entry key="atom" value="application/atom+xml" /> 
      <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/jsp/" /> 
       <property name="suffix" value=".jsp" /> 
      </bean> 
     </list> 
    </property> 
    <property name="defaultViews"> 
     <list> 
      <bean 
       class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> 
     </list> 
    </property> 
</bean> 

<mvc:resources mapping="/css/**" location="/css/" /> 
<mvc:resources mapping="/img/**" location="/img/" /> 
<mvc:resources mapping="/js/**" location="/js/" /> 

</beans> 

我的控制器是以下

package org.package.servletname; 

import java.util.LinkedList; 
import java.util.List; 

import org.package.servletname.orm.*; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 

@Controller 
@RequestMapping("/ajax") 
public class JSONGetController 
{ 
@RequestMapping(value = "/getproducts", method = RequestMethod.GET) 
public @ResponseBody 
List<Product> JSONGetProducts() 
{ 
    List<Product> productList = null; 
    Product p = new Product(); 
    p.setName("ProductName"); 
    productList = new LinkedList<Product>(); 
    productList.add(p); 
    return productList; 
} 
} 

感謝

回答

2

Jackson在CL缺失asspath

+0

謝謝..這真的很簡單:) – gc5

+0

除此之外,我不得不檢查訂單和出口部分的庫,看到答案在http://stackoverflow.com/questions/13570759/android-spring-jackson-mapping-noclassdeffounderror –

+11

我不明白答案。 – Dimillian