我有简单的 JAX-RS 服务器应用程序:
@GET
@Path("/getImage/{key}")
@Produces("image/jpeg")
public final BufferedImage getImageResource(@PathParam("key") String key) {
final File file = new File(key); // the key will be "cat.jpeg" e.t.c.
final BufferedImage image = ImageIO.read(new FileInputStream(file));
return image;
}
将war文件部署到tomcat服务器(6.0)后,我下一步:
http://localhost:8080/resource-service/getImage/cat.png
问题:
1)在新文件(键)上,它将转到tomcat根目录。我想在类周围的项目目录中拥有类似于默认根文件夹的资源。
2)据我了解,不允许返回 BufferedImage,我收到 500 错误消息:
HTTP Status 500 - Could not find MessageBodyWriter for response object of type: java.awt.image.BufferedImage of media type: image/jpeg
我会很感激任何建议,链接。提前致谢!