Java 尝试以xml形式获取所有国家/地区返回406不可接受
我已经编写了一个简单的web服务,在这里我能够成功地从数据库值返回json,现在我正试图从数据库中以xml的形式返回数据库值,但得到的406是不可接受的。这是我诚实的尝试: 控制器代码段Java 尝试以xml形式获取所有国家/地区返回406不可接受,java,xml,spring,rest,maven,Java,Xml,Spring,Rest,Maven,我已经编写了一个简单的web服务,在这里我能够成功地从数据库值返回json,现在我正试图从数据库中以xml的形式返回数据库值,但得到的406是不可接受的。这是我诚实的尝试: 控制器代码段 @RestController public class CountryController { @Autowired CountryService countryService; @RequestMapping(value = "/getAllCountries", method
@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;
}
@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();
}
一个pom.xml的片段,显示我用于序列化以检索xml数据的依赖库
<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>
com.fasterxml.jackson.core
杰克逊数据绑定
2.4.1
com.sun.xml.bind
jaxb impl
2.2.11
com.sun.xml.bind
jaxb内核
2.2.11
编辑以显示XML配置文件
<?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/" />
尝试使用rest客户端执行上述操作时,返回406 not acceptable(不可接受)。请帮忙
配置它支持将对象转换为XML文件或从XML文件转换对象在映射注释之后使用@ResponseBy注释那么您是否使用了它的支持将对象转换为XML文件或从XML文件转换对象元素“mvc:annotation driven”的前缀“mvc”没有绑定。我正在使用它issue@Kingston您使用的是xml配置还是java?@Kingston如果您使用的是xml配置,我可以看看您的应用程序配置文件xml配置吗