私はSpringインテグレーションを使用してFTPを介してリモートディレクトリにファイルをアップロードするWebプロジェクトを行っています。ただし、FTPプロパティはデータベースから動的にロードされ、要求ごとに異なる場合があります。単純なアプローチ:ダイナミックFTPプロパティを使用したSpringインテグレーションのアップロード
最初DefaultFtpSessionFactory
豆作成:
@Bean
public DefaultFtpSessionFactory defaultFtpSessionFactory() {
return new DefaultFtpSessionFactory();
}
IntegrationFlow
がBean:
@Bean
public IntegrationFlow integrationFlow(DefaultFtpSessionFactory defaultFtpSessionFactory) {
// Flow config
}
がコントローラにこのBeanを注入してプロパティ設定:もちろん
@Autowired
private DefaultFtpSessionFactory defaultFtpSessionFactory;
@Autowired
private FtpConfigService ftpConfigService;
@RequestMapping(value = "upload", method = RequestMethod.GET)
public RequestEntity<String> upload() {
defaultFtpSessionFactory.setHost(ftpConfigService.getHost());
// Set other properties
// ... and upload file
return new RequestEntity<>(HttpStatus.OK);
}
を、この競争状態があるので、悪い考えです(2つのreque同じ時間にシングルトンDefaultFtpSessionFactory
にアクセスできます)。だから、私はこれをどのようにして安全に達成することができますか?
あなたができることは、あなたのftpペイロードと、フロー内のsessionFactoryを更新するために使用できるセッションプロパティを含むMessageを作成することです。 – JEY