Pergunta

I have been reading BalusC's guide on how to use a seperate Servlet to attach a byte[] representation of an Image to an HttpServlet response via a BufferedOutputStream, and appreciate that this is neccessary because an HTML Img tag refers to a URL / cannot accept a stream of bytes.

http://balusc.blogspot.co.uk/2007/04/imageservlet.html

The problem I am having with adapting BalusC's example is that I use Spring and Spring Data JPA behind JSF, so my ImageDAO is actually a Spring Data JPA Repository that is behind a different Servlet (the JSF Servlet).

Is there any way that I can get a handle to the ImageRepository which is curated by my Spring container behind the JSF Servlet?

I anticipate that this is a common stumbling block for those using IoC for their applications and resorting to writing a seperate Servlet to appease the needs of the HTML Img tag. Writing a seperate Servlet and trying to get a handle to another feels like an appeasment of design / a dirty hack!

Foi útil?

Solução

The two magic lines appear to be:

WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    yourRepository = (YourRepository) context.getBean("yourRepository");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top