[ https://issues.apache.org/jira/browse/WW-4559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14987441#comment-14987441 ]
Rene Gielen commented on WW-4559: --------------------------------- It looks like your autowiring strategy is set to "type". See https://struts.apache.org/docs/spring-plugin.html#Autowiring Please try to set your strategy explicitly to "name" or "no" and check again. > Define a bean of java.io.FileInputStream in Spring makes the Struts stream > result not work > ------------------------------------------------------------------------------------------ > > Key: WW-4559 > URL: https://issues.apache.org/jira/browse/WW-4559 > Project: Struts 2 > Issue Type: Bug > Components: Dispatch Filter > Reporter: Alireza Fattahi > Fix For: 2.3.x > > > In a strust2 + Spring 4 project > Consider a simple action with stream result > {code:title=Bar.java|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 jasper > exportInputStream = buildExportInputStream(); > LOG.debug("Exporting to {} file ", getFilename()); > return SUCCESS; > } > {code} > This works fine, > Now define a bean > {code:xml} > <bean id="sampleStream" class="java.io.FileInputStream" > > <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 (v6.3.4#6332)