I'm trying to do a ftp poller with the help of Spring integration and the poller works great with the xml configuration. Now开发者_运维知识库 I would like to be able to dynamically set some properties of the poller like the cron-expression or the polling rate to make it configurable by java code and link it to a web interface.
I have seen a lot of topics around the subject but nothing really clear to do that.
Is there a classic way of doing that ? Can it be done with SpeL ?My bean poller declaration in XML is as follows :
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel" session-factory="ftpClientFactory"
filename-regex=".*\.tmp$" auto-create-local-directory="true"
delete-remote-files="false" remote-directory="/cft-polling" local-directory="file:target/ftp-output" >
<int:poller fixed-rate="1000" />
</int-ftp:inbound-channel-adapter>
<int:channel id="ftpChannel">
<int:queue />
</int:channel>
I'm not sure there is enough here for a solid answer, but assuming that the ftp poller is defined and managed in the spring container, and assuming there are proper accessores to modify it's properties...that you will be able to change it's setting just like you would any other object.
First you would have to get a reference of the spring managed object, you can do this by having one of your classes implement ApplicationContextAware thereby exposing the Spring context.
Then it's just a matter of getting the bean from the context and updating it's property.
public class MyManagedClass implements ApplicationContextAware {
private ApplicationContext springContext;
public void changeBeansProperty(){
MyFtpPoller poller = (MyFtpPoller) springContext.getBean("ftpInbound");
poller.setCronExpress("12 12 * * * *");
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.springContext = applicationContext;
}
}
精彩评论