RESTful JSON 서비스에 대한 Spring MVC 3.2 비동기 지연 결과를 사용하려고합니다.JSON이 스프링 MVC 3.2를 사용하여 잘못 반환됩니다. 지연된 결과
동기 방식 사용 :
@ResponseBody
@RequestMapping(value = "/catalogs", method = RequestMethod.GET, produces = "application/json")
public DeferredResult<Entry> catalogs() {
Entry entry = new Entry();
entry.timestamp = System.currentTimeMillis();
entry.summary = "Hello World!";
entry.body = new HashMap<String, Object>();
entry.body.put("key1", "value1");
entry.body.put("key2", "value2");
entry.body.put("key3", "value3");
DeferredResult<Entry> result = new DeferredResult<Entry>();
result.setResult(entry);
return result;
}
나는 다음과 같은 얻을 : 비동기 방식 (인위적인 예)를 사용하여
{"timestamp":1359721240340,"summary":"Hello World!","body":{"key3":"value3","key2":"value2","key1":"value1"}}
:
@ResponseBody
@RequestMapping(value = "/catalog", method = RequestMethod.GET, produces = "application/json")
public Entry catalog() {
Entry entry = new Entry();
entry.timestamp = System.currentTimeMillis();
entry.summary = "Hello World!";
entry.body = new HashMap<String, Object>();
entry.body.put("key1", "value1");
entry.body.put("key2", "value2");
entry.body.put("key3", "value3");
return entry;
}
을 나는 다음과 같은 JSON 결과를 얻을 수 :
{}{"timestamp":1359721240340,"summary":"Hello World!","body":{"key3":"value3","key2":"value2","key1":"value1"}}
그래서 접두사가 붙은 빈 개체 (예 : {})? 분명히 바보 같은 일을하고 있습니까? 아니면 MappingJackson2JsonView
이 새로운 비동기 기능과 잘 맞지 않습니까?
F.Y.I 여기 내 스프링 MVC 빈 구성입니다 :
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="contentNegotiationManager">
<bean class="org.springframework.web.accept.ContentNegotiationManager" />
</property>
<property name="defaultViews">
<list>
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
</list>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="2" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
비어있는 {}은 지연이고, 채워진 것은 응답입니다 ... j/k! 이것은 동일한 문제가 될 수 있는지 모르겠지만, 나는 그것을 들어 그냥 떠날 것이다 : http://stackoverflow.com/questions/14376285/reverse-ajax-using-deferredresult-of-spring-3-2 -0-release-not-working-in-ie – CodeChimp