【发布时间】:2015-10-12 10:25:41
【问题描述】:
我已经尝试了很多方法来从控制器函数中返回一个文件。
这是我的功能:
@RequestMapping(value = "/files", method = RequestMethod.GET)
@ResponseBody public FileSystemResource getFile() {
return new FileSystemResource(new File("try.txt"));
}
我收到此错误消息:
无法写入 JSON:
没有找到类 java.io.FileDescriptor 的序列化程序,也没有发现创建 BeanSerializer 的属性
(为避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS))
(通过参考链:
org.springframework.core.io.FileSystemResource[\"outputStream\"]->java.io.FileOutputStream[\"fd\"]);
嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.FileDescriptor and no properties found to create BeanSerializer
(为避免异常,请禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS))
(通过引用链:org.springframework.core.io.FileSystemResource[\"outputStream\"]->java.io.FileOutputStream[\"fd\"])
有人知道如何解决吗?
而且,我应该如何从客户端发送(JavaScript、jQuery)?
【问题讨论】:
-
您注册了哪些
HttpMessageConverter实例? -
ammm...,我是 Spring 新手。你能解释一下吗?
-
我想看看你的 MVC 配置。
-
还告诉我们您的客户端发送了哪些请求标头。
-
在客户端我使用了简单的 jQuery 获取:
jQuery.get("http://localhost:8086/vos-api/StreamProcessingDiagrams/v1/setting/createFOO", function( data ) { jQuery( ".result" ).html( data ); });
标签: java xml spring file spring-mvc