2012-10-19 17 views
0

Jackson이 Spring 애플리케이션에서 작동하도록하는 데 문제가 있습니다.Spring in Spring MVC 3.1.2

내가 사용

  • 스프링 MVC는 3.1.2
  • 잭슨의 I/WEB-INF/lib 디렉토리/폴더에 잭슨 라이브러리를 추가 한

ASL 매퍼를 한 묶음 내 봄 설정 파일에 추가되었습니다. 컨트롤러

봄-config.xml에

<!-- language: xml--> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 

<mvc:annotation-driven /> 

<context:component-scan base-package="com.mason.server.controller" /> 

<bean 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix"> 
     <value>/WEB-CONTENT/</value> 
    </property> 
    <property name="suffix"> 
     <value>.jsp</value> 
    </property> 
</bean> 

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="WEB-INF/messages/messages" /> 
</bean> 

기능

<!-- language: java --> 
@RequestMapping(value = "/get_json", method = RequestMethod.GET, headers = "Accept=*/*") 
public @ResponseBody List<String> getTechList() { 
    List<String> countryList = new ArrayList<String>(); 

    countryList.add("test"); 

    return countryList; 
} 

내가 localhost로 이동 : 8888/get_json 내가 오류를 406

I를 얻을 수 인터넷에서 솔루션을 시도했지만 그 중 아무 것도 작동하지 않는 것 같습니다. 어떤 도움을 주시면 감사하겠습니다!

추신 : 저는 Google App Engine 및 스프링 보안과 함께 Spring MVC를 사용합니다.

+0

, 내가 곧 내 솔루션을 게시 할 예정입니다 – areont

답변

2

나는 2 일 후에 작동하게했다. 내 라이브러리에 jackson-core-asl-1.9.10을 추가하는 것을 잊었으며 jQuery를 사용하여 요청을하면 모든 것이 잘 작동했습니다. 그것은 브라우저에서 링크로가는 일을하지 않지만, 지금은 괜찮아요.

MVC-config.xml에

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 

<context:component-scan base-package="com.mason.server.controller" /> 

<mvc:annotation-driven /> 

<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.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <property name="prefix" value="/WEB-CONTENT/"/> 
     <property name="suffix" value=".jsp"/> 
     </bean> 
    </list> 
    </property> 
    <property name="defaultViews"> 
    <list> 
     <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> 
     <property name="prefixJson" value="true"/> 
     </bean> 
    </list> 
    </property> 
</bean> 

test.jsp를 내가 일하고있어

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 
<html xmlns=" http://www.w3.org/1999/xhtml "> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Request json test</title> 
<script src="http://code.jquery.com/jquery-1.5.js"></script> 
<script> 

$(document).ready(function(){ 
    //attach a jQuery live event to the button 
    $('#getdata-button').live('click', function(){ 
     $.getJSON('/get_json', function(data) { 
      //alert(data); //uncomment this for debug 
      //alert (data.item1+" "+data.item2+" "+data.item3); //further debug 
      $('#showdata').html("<p>"+data+"</p>"); 
     }); 
    }); 
}); 

</script> 

</head> 
<body> 
<a href="#" id="getdata-button">Get JSON Data</a> 
<div id="showdata"></div> 
</body> 
</html>