mule read single file from classpath during flow

前端 未结 8 1718
渐次进展
渐次进展 2020-12-05 11:13

Is there an easy way to configure a Flow to read a single file from the classpath one time? I don\'t need to poll for a file. I just need to read a known file and set its co

相关标签:
8条回答
  • 2020-12-05 11:57

    For some reason I cannot make the solution proposed by David Dossot to work. I was inspired by this answer and came up with another solution

    <spring:bean id="myResource" class="org.apache.commons.io.IOUtils" factory-method="toString">
        <spring:constructor-arg value="classpath:path/to/myResource.txt" type="java.io.InputStream"/>
    </spring:bean>
    

    and then you can use set-payload in the following way

    <set-payload value="#[app.registry.myResource]" doc:name="Set Payload"/>
    

    which will result in setting the payload with the content of the file as a String.

    This method has the advantage that the content of the resource file is loaded only once into a bean of type String. So if your set-payload statement is executed frequently, this could improve performance.

    0 讨论(0)
  • 2020-12-05 12:06
    <parse-template location="my-resurce.txt" doc:name="Load resource as a String"/>
    

    The file can perfectly contain no MEL expression whatsoever, in which case it's actually loaded as it is, and it becomes the payload.

    0 讨论(0)
提交回复
热议问题