我使用XStream解组Data.xml文件。 当我用main()函数运行它时,它完美地工作,但是当我尝试通过启动应用程序运行它时,它会给我带来UnknownFieldException。仅在春季启动应用程序中发生UnknownFieldException
产生的原因:com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter $ UnknownFieldException:没有这样的领域workshop.tokenizer.data.Attributes.attribute ----调试信息---- 消息:没有此字段workshop.tokenizer.data.Attributes.attribute 字段:属性 类:workshop.tokenizer.data.Attributes required-type:workshop.tokenizer.data.Attributes converter-type:com.thoughtworks.xstream.converters。 reflection.ReflectionConverter class [1]:workshop.tokenizer.data.DataObj class [2]:java.util.ArrayList 转换器型[1]:com.thoughtworks.xstream.converters.collections.CollectionConverter 类[3]:workshop.tokenizer.wrappers.DataObjects 版本:1.4.9
当我在调用此方法,创建主要对象会失败,此异常,但如果我叫从同线“公共静态无效的主要...”它完美
@RequestMapping(method = RequestMethod.POST, value = "/test")
public ResponseEntity<SFRecord> execute(@RequestBody RequestDto json)
throws ClassNotFoundException, SQLException, FileNotFoundException {
Request request = json.convert();
Main main = new Main();
RequestObj reqObj = main.execute(request.getSentence());
ResponseEntity<SFRecord> result = restTemplate.exchange(parserUrl, HttpMethod.POST,
new HttpEntity<RequestObj>(reqObj), SFRecord.class);
return result;
}
里面主要是使用此行来解组data.xml中
FileReader reader = new FileReader("Files/Data.xml");
objects = (DataObjects) xstream.fromXML(reader);
有什么想法为什么这种奇怪的行为?
感谢
更新
我注意到XStreamAlias注释被忽略了,所以我加了 xstream.autodetectAnnotations(真); 但现在我得到这个异常:
java.lang.ClassCastException: wrappers.DataObjects cannot be cast to wrappers.DataObjects
我用这条线来解组XML:
FileReader reader = new FileReader("Files/Data.xml");
DataObjects objects = (DataObjects) xstream.fromXML(reader);