user21597761
user21597761

Reputation:

Spring boot keep properties even after new deploy

Currently, I am sending app crashes logs of Android app via HTTP to my server (acra) and my server saves them in properties like this:

@RestController
public class EndlessBlowReportController {
    
    public int counter;

    @Autowired
    public static final Properties defaultProperties = new Properties();

    @PostMapping("/add_report")
    public void addReport(@RequestBody String report) {
        try {
            JSONObject jsonObject = new JSONObject(report);
            defaultProperties.put(counter, report);
            counter++;

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    @GetMapping("/get_reports")
    public List<String> getReports() {
        List<String> reports = new ArrayList<>();
        try {
            for(int i=0;i<defaultProperties.size();i++) {
            reports.add((String)defaultProperties.get(i));
            }
        } catch (Exception ex) {
        }
        return reports;
    }
}

and it works fine until I deploy a new version of the server.

How can I keep my properties even after deploy?

Upvotes: 0

Views: 72

Answers (1)

Karl Dahlgren
Karl Dahlgren

Reputation: 364

The properties are only stored in memory and won't be persisted to any permanent storage, such a file or database. My recommendation would be to not store this information in properties, but instead store it in a database, or alternatively in the file storage as a file.

For example, if you went with the file solution, you could load the file during the startup and update the file each time you get new reports. By doing so, you would persist the information and it wouldn't disappear each time you restart your server.

I hope you find this answer helpful.

Good luck!

Upvotes: 1

Related Questions