- @Scheduled(fixedRate = 10 * 1000)
- public void checkConfigFileChanges() {
- long timestamp = new File(localConfigurationFilePath).lastModified();
- if (configFileLastModification != 0 && timestamp != configFileLastModification) {
- logger.info("Restarting due to change in the file {}", localConfigurationFilePath);
- restartApplication();
- }
- configFileLastModification = timestamp;
- }
-
- private static void restartApplication() {
- if (applicationContext == null) {
- logger.info("Cannot restart in unittest");
- return;
- }
- ApplicationArguments args = applicationContext.getBean(ApplicationArguments.class);
-
- Thread thread = new Thread(() -> {
- applicationContext.close();
- applicationContext = SpringApplication.run(Application.class, args.getSourceArgs());
- });
-
- thread.setDaemon(false);
- thread.start();
- }