struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rene Gielen (JIRA)" <>
Subject [jira] [Commented] (WW-4559) Define a bean of in Spring makes the Struts stream result not work
Date Wed, 04 Nov 2015 08:26:27 GMT


Rene Gielen commented on WW-4559:

Struts treats dependency injection as a first class citizen, so injection candidates are respected
even in framework classes. I think your case is quite special, since I've never seen someone
declaring an InputStream as managed bean before. I must also admit that I doubt this is a
best practice.

Anyway, we might want to look into this to check wether such an injection of a matching managed
bean is viable in StreamResult or should be prevented.

I don't see particular problems arise from setting alwaysRespect=true. Since the advent of
@Inject I'd always prefer to limit autowiring where possible in favor for explicit declarations.

> Define a bean of in Spring makes the Struts stream result not
> ------------------------------------------------------------------------------------------
>                 Key: WW-4559
>                 URL:
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter
>            Reporter: Alireza Fattahi
>            Priority: Minor
>             Fix For: 2.5.x
> In a strust2 + Spring 4 project
> Consider a simple action with stream result 
> {|borderStyle=solid}
> @Action(value = "sample-export", 
>         results = { @Result(name = "success", type = "stream", params = {
>         "inputName", "exportInputStream", "contentType",
>         "${exportContentType}; charset=UTF-8", "Content-Disposition",
>         "attachment; filename=\"${filename}\"", "contentDisposition",
>         "attachment; filename=\"${filename}\"", "bufferSize", "2048" }) })
> public String export() throws ClientException {
>     //buildExportInputStream() creates and returns new ByteArrayOutputStream by using
>     exportInputStream = buildExportInputStream();
>     LOG.debug("Exporting to {} file ", getFilename());
>     return SUCCESS;
> }
> {code}
> This works fine,
> Now define a bean 
> {code:xml}
>  <bean id="sampleStream" class="" >
>         <constructor-arg  value="c:/sample.jks"/>  
>   </bean>
> {code}
> The export will not work correctly any more, first time you get the c:/sample.jks as
file and then an  error which same stream already closed.
> I have found that the sampleStream will be autowired to org.apache.struts2.dispatcher.StreamResult
and I see this log:
> {panel:title=LOG|borderStyle=dashed|borderColor=#ccc|titleBGColor=#F7D6C1|bgColor=#FFFFCE}
> DEBUG ort.DefaultListableBeanFactory Returning cached instance of singleton bean 'sampleStream'
> DEBUG ort.DefaultListableBeanFactory Autowiring by type from bean name 'org.apache.struts2.dispatcher.StreamResult'
via constructor to bean named 'sampleStream'
> {panel}
> This mistaken autowired is the source of problem ! Is there any workaround. And by the
way, why the sampleStream is autowired here !

This message was sent by Atlassian JIRA

View raw message