title: Spring MVC: How to return image in @ResponseBody?
body: <p>I'm getting image data (as <code>byte[]</code>) from DB. How to return this image in <code>@ResponseBody</code> ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I did it without <code>@ResponseBody</code> using <code>HttpServletResponse</code> as method parameter:</p>
  
  <pre><code>@RequestMapping("/photo1")
  public void photo(HttpServletResponse response) throws IOException {
      response.setContentType("image/jpeg");
      InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg");
      IOUtils.copy(in, response.getOutputStream());
  }
  </code></pre>
  
  <p>Using <code>@ResponseBody</code> with registered <code>org.springframework.http.converter.ByteArrayHttpMessageConverter</code> converter as @Sid said doesn't work for me :(.</p>
  
  <pre><code>@ResponseBody
  @RequestMapping("/photo2")
  public byte[] testphoto() throws IOException {
      InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg");
      return IOUtils.toByteArray(in);
  }
  </code></pre>