ich einen einfachen Web-Service geschrieben habe, wo ich in der Lage gewesen json aus den Datenbankwerten erfolgreich zurückzukehren und an diesem Punkt Ich versuche, die Datenbank Wert als XML aus der Datenbank zurück, sondern 406 nicht akzeptabel zu bekommen. Das ist mein ehrlicher Versuch:versuchen, getAllCountries als XML zurückgibt 406 nicht akzeptabel
Controller Schnipsel
@RestController
public class CountryController {
@Autowired
CountryService countryService;
@RequestMapping(value = "/getAllCountries", method = RequestMethod.GET, headers = "Accept=application/xml")
public List<Country> getCountries() {
List<Country> listOfCountries = countryService.getAllCountries();
return listOfCountries;
}
das ist mein pojo Klasse Schnipsel
@XmlRootElement(name="Country")
@Entity
@Table(name="COUNTRY")
public class Country{
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.AUTO)
int id;
@Column(name="countryName")
String countryName;
@Column(name="population")
long population;
public Country() {
super();
}
ein Ausschnitt aus pom.xml zeigt abhängige Bibliotheken ich für die bin mit Serialisierung zum Abrufen von XML-Daten
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
editierte XML CONFIG FILE ein Rest-Client oben mit kehrt die ZEIGEN 406 nicht akzeptabel
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<mvc:annotation-driven/>
<resources mapping="/resources/**" location="/resources/" />
Bei dem Versuch. Bitte helfen.
Verwendung @ResponseBody Anmerkung nach dem Mapping-Annotation – Boldbayar
haben Sie dabei auch seine Stützen Objekt zu/von XML-Datei –
Boldbayar