如何在运行时在Spring MVC中重新加载配置对象

时间:2019-06-06 11:45:47

标签: java spring spring-mvc spring-config

我有一个配置类FTPSchedullingConfiguration,该类在应用程序实例化时初始化,并从表中获取数据,以便在给定的调度表达式上启动调度程序。

而且我的问题不是像Reloading/Refreshing Spring configuration file without restarting the servlet container这样重复,因为我没有任何XML文件,我的应用程序基于注释,这里每个类都以.class formate进行编译,因此我们无法更改任何代码在运行时。

@Configuration
@EnableScheduling
public class FTPSchedullingConfiguration {

@Autowired
private FTPTransferServiceInterface ftpTransferServiceInterface;

@Bean
public String getCronFTPTransferValue()
{
    return ftpTransferServiceInterface.getFTPTransferById((long) 1).getTransferCroneTime();
}

 @Scheduled(cron="#{@getCronFTPTransferValue}")
 public void ftpTransfer() {
    ftpTransferServiceInterface.transferFTPRecording();
 }
}

但是当我更改表的Schedule Expression时,则按计划的时间没有更改。如果我重新启动服务器,则更改了表达式加载。

通过使用updateFTP()

@RequestMapping(value= {"/updateFTPTransfer"})
private String updateFTP(...){
  ftpTransferServiceInterface.updateFTP(ftpDomain);
    //here i want to change the value of @Scheduled 
}

我的实际需求就像当时我通过updateFTP(...){...}更改表中的Expression值时一样,我的计划值也更改了(OR)Refreshed FTPSchedullingConfiguration类。

谢谢。

0 个答案:

没有答案
相关问题