0

I have an existing properties file like below

csv.requireresync=true

There are two actions in the system that will get and set value to it.

  1. Every 5 minutes there will a process that will set the csv.requireresync to false.

  2. Every 2 weeks there will be a process that will set the csv.requireresync to true.

I tried to do the above using @Component but not working

@Component
@ConfigurationProperties(prefix = "csv")
public class ResyncConfig {

    private boolean requireresync;

    public void setRequireresync(boolean requireresync) {
        this.requireresync = requireresync;
    }

    public boolean isRequireresync() {
        return requireresync;
    }
}

The idea is when the I call setRequireresync to true the value must reflect in the application.properties file.

Is it possible achieve what I want ? or do I need a extra configuration file for that ?

abiieez
  • 3,139
  • 14
  • 57
  • 110
  • Possible duplicate of [Set/override Spring / Spring Boot properties at runtime](https://stackoverflow.com/questions/27919270/set-override-spring-spring-boot-properties-at-runtime) – Roland Weisleder Jul 24 '18 at 07:34
  • You do know that if you simply set that property in `ResyncConfig` it will be shared accross whole application? CSV is just for bootstraping initial values. – Antoniossss Jul 24 '18 at 07:42

1 Answers1

1

Just set required values directly to ResyncConfig isntance. It is shared across application (if not using Scopes its singleton) and any changes made to it will be in effect. File is only for bootstraping config class with initial settings.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • If the application restarted. The new value should not be lost. Lets say the property in the file originally set to true. Then I set it to false through code. Will the properties file now updated to false ? – abiieez Jul 24 '18 at 09:26
  • How to change settings on runtime? - like I described above. How to persist it between restarts? - Update config file. – Antoniossss Jul 24 '18 at 09:33