Я сделал простой веб-сервис для отдыха с Spring Boot 1.2.5, и он отлично работает для json, но я не могу заставить эту работу возвращать xml.Spring Boot REST с поддержкой XML
Это мой контроллер:
@RestController
..
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
@ResponseStatus(HttpStatus.OK)
public List<Activity> getAllActivities() {
return activityRepository.findAllActivities();
}
Когда я называю его с Accept: применение/JSON все работает, но когда я пытаюсь с применением/XML я получить HTML с 406 ошибкой и сообщение:
The resource identified by this request is only capable of generating responses
with characteristics not acceptable according to the request "accept" headers.
Мои объекты модели:
@XmlRootElement
public class Activity {
private Long id;
private String description;
private int duration;
private User user;
//getters & setters...
}
@XmlRootElement
public class User {
private String name;
private String id;
//getters&setters...
}
Мой pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
мне нужны какие-то дополнительные банки в моей pom.xml, чтобы сделать эту работу делать? Я попытался добавить jaxb-api или jax-impl, но он не помог.
Вы уверены, что вы устанавливаете его в 'приложения/xml' и не что-то другое? Включите ведение журнала отладки и посмотрите, что происходит внутри. –
Можете ли вы поделиться своим POM-файлом !!! – Avis
@Avis i paste my pom.xml – jgr