image-download - wrapping resource inside response entity

This commit is contained in:
Slavisa Baeldung 2016-05-10 16:56:17 +02:00
parent d2ca517fde
commit fe22d59d06
1 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,9 @@ public class ImageController {
@RequestMapping(value = "/image-resource", method = RequestMethod.GET)
@ResponseBody
public Resource getImageAsResource() {
return new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg");
public ResponseEntity<Resource> getImageAsResource() {
final HttpHeaders headers = new HttpHeaders();
Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg");
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
}