以下是我为文件轮询功能配置的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方法中或通过任何其他方式修改目录。
请帮忙!
您尝试使用的通用机制将起作用,因为在评估目录表达式之前会调用文件名生成器。
但是,您有两个实例。您确实定义了@Component
(并且您正在使用组件扫描,您将有两个GetOutPath
-aPath
和outPathBean
实例。
表达式正在使用您未更改的实例。
您需要注入在表达式中使用的相同bean实例。