修改出站通道适配器弹簧集成中的输出目录

时间:2014-08-30 13:30:42

标签: spring-integration

以下是我的文件轮询功能配置xml。我有时需要更改输出目录。

<int-file:inbound-channel-adapter id="filesIn" directory="file:${paths.root}" channel="abc" >
        <int:poller id="poller" fixed-delay="5000"/>

    </int-file:inbound-channel-adapter>
    <int:channel id="abc"/>

    <int-file:outbound-channel-adapter channel="abc" id="filesOut" 
    directory-expression="@aPath.getPath()"
    delete-source-files="true" 
    filename-generator ="filenameGenerator"/>

<bean id="filenameGenerator" class="com.dms.util.FileNameGenerator"/>

 @Override
    public String generateFileName(Message<?> message)
    {

我已经尝试设置已配置的bean属性的值。 这是

的附加配置
<bean name="aPath" class="com.dms.util.GetOutPath">
    <property name="path" value="${paths.destination}"/>
</bean>  

paths.destination来自属性文件。 在generateFileName方法中,我添加了用于更改属性值的代码,如下所示

@Autowired
    private GetOutPath outPathBean;

对于bean:

@Component("outPathBean")

并在我的代码中

outPathBean.setPath(newFolder);

我的调试显示属性的值不会改变。我的问题是,如何在generateFileName方法中或通过任何其他方式修改目录。

请帮忙!

1 个答案:

答案 0 :(得分:0)

您尝试使用的一般机制将起作用,因为在评估目录表达式之前文件名生成器是calle。

但是,您有两个实例已经定义了@Component(并且您正在使用组件扫描,您将有两个GetOutPath - aPath和{{1}的实例}。

表达式使用的是您没有更改的实例。

您需要注入在表达式中使用的相同bean实例。