鉴于这种非常基本的春季启动应用程序:XML转换失败与Spring引导RestTemplate
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
与Maven依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
而且类型
@XmlRootElement(name = "ICECAT-interface")
public class IceCatResponse {
private Product product;
/* getters, setters omitted */
}
@XmlRootElement(name = "Product")
public class Product {
private int code;
/* getters, setters omitted */
}
冰壶所需的URL产量
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ICECAT-interface SYSTEM "http://data.icecat.biz/dtd/ICECAT-interface_response.dtd">
<!-- source: Icecat.biz 2017 -->
<ICECAT-interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://data.icecat.biz/xsd/ICECAT-interface_response.xsd">
<Product Code="1"
HighPic="http://images.icecat.biz/img/norm/high/21900316-8020.jpg"
...>
...
</Product>
</ICECAT-interface>
我试图通过执行此RestTemplate电话,并希望得到解析为IceCatResponse
类型的对象结果:
ResponseEntity<IceCatResponse> result = this.httpTemplate.exchange(url, HttpMethod.GET, request, IceCatResponse.class);
与request
只包含一个认证头。
这导致错误消息
无法读取HTTP消息: org.springframework.http.converter.HttpMessageNotReadableException: 未能进行解组为[类 de.mischok.konfigurator.spikeicecat.model .IceCatResponse]:null; 嵌套异常是javax.xml.bind.UnmarshalException - 带有链接的异常:[org.xml.sax.SAXParseException; lineNumber:2; columnNumber:10; DOCTYPE IST nichtzulässig,德恩DAS特征 “http://apache.org/xml/features/disallow-doctype-decl” AUF“真” gesetzt北京时间]
我想响应的DOCTYPE部分是我的问题,没有人知道,我如何能春配置忽略这部分?