java - 即使在新部署之后,Spring Boot 也会保留属性
问题描述
目前,我正在通过 HTTP 将 Android 应用程序的应用程序崩溃日志发送到我的服务器(acra),我的服务器将它们保存在如下属性中:
@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;
}
}
在我部署新版本的服务器之前它工作正常。
即使在部署之后,我如何才能保留我的属性?
解决方案
这些属性仅存储在内存中,不会持久保存到任何永久存储中,例如文件或数据库。我的建议是不要将此信息存储在属性中,而是将其存储在数据库中,或者作为文件存储在文件存储中。
例如,如果您使用文件解决方案,您可以在启动期间加载文件并在每次获得新报告时更新文件。通过这样做,您将保留信息,并且每次重新启动服务器时它都不会消失。
我希望你觉得这个答案有帮助。
祝你好运!
推荐阅读
- r - 使用向量作为数据帧的参考,如何将函数应用于向量中的所有数据帧?
- sql - 基于两个聚合函数返回计算字段的结果
- javascript - 如何使用 jQuery 将列表项添加到列表中?
- java - pmd规则:静态导入过多可能导致unitTest中代码乱码不违反
- python - 网页抓取。没有得到我想要的
- html - 星云响应式布局
- javascript - 尝试使用单个按钮功能将播放列表从数组添加到另一个组件
- javascript - 序列化的 select2 值在 asp.net mvc 的控制器中不可用
- android - 我应该在 Android sdkmanager CLI 上进行哪些更改以允许从 artifactory 下载?
- react-native - 无限调用 RenderFooter