Spring Boot REST mit XML-Unterstützung

Habe ich ein einfaches REST webservice mit Spring Boot 1.2.5 und es funktioniert gut für JSON aber ich kann nicht machen diese Arbeit, um die XML zurückgeben.

Dies ist mein controller:

@RestController
..
@RequestMapping(method = RequestMethod.GET,  produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
@ResponseStatus(HttpStatus.OK)
public List<Activity> getAllActivities() {
    return activityRepository.findAllActivities();
}

Wenn ich es mit Accept: application/json alles funktioniert, aber wenn ich versuche mit application/xml ich einige HTML-406-Fehler und die Meldung:

The resource identified by this request is only capable of generating responses 
with characteristics not acceptable according to the request "accept" headers.

Mein Modell Objekte:

@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...
}

Meine 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>

Brauche ich einige zusätzliche Gläser in meine pom.xml um diese Arbeit zu machen? Ich habe versucht, das hinzufügen jaxb-api oder jax-impl aber es hat nicht geholfen.

Sind Sie sicher, dass Sie es zu application/xml und nicht etwas anderes? Aktivieren Sie die debug-Protokollierung und sehen, was passiert im inneren.
Können Sie teilen Sie Ihre POM-Datei!!!
ich füge meine pom.xml

InformationsquelleAutor jgr | 2015-09-18

Schreibe einen Kommentar