Я использую <mvc:annotation-driven />
Spring (3.0) конфигурацию (без ContentNegotiatingViewResolver ).Согласно документации Spring 3 поддерживает JSON и XML.Использование @ResponseBody
в методе обработчика, как показано ниже, дает ответ JSON.Как контролировать ответ для получения XML или JSON?
@RequestMapping("/data")
public @ResponseBody User getUser() {
return new User();
}
EDIT
Используемые зависимости Maven:
<!-- xml -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.8</version>
</dependency>
<!-- json -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.8.1</version>
</dependency>
Отладка AnnotationDrivenBeanDefinitionParser => jaxb2Present = true, jacksonPresent = true