Я использую конфигурацию <mvc:annotation-driven />
Spring (3.0) (без ContentNegotiatingViewResolver). Согласно документация Spring 3 поддерживает JSON и XML. Использование @ResponseBody
в методе обработчика, как показано ниже, дает ответ JSON. Как контролировать ответ, чтобы получить XML или JSON?
@RequestMapping("/data")
public @ResponseBody User getUser() {
return new User();
}
ИЗМЕНИТЬ
Используемые зависимости 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
http://server/.../json
возвращал JSON иhttp://server/.../data
возвращал XML, используя аннотации Spring 3. - person marioosh   schedule 20.06.2011