[英]How can I create a table in my postgres db with Spring Boot?
[英]How can I “restore” data in DB after start Spring boot?
启动Spring Boot后,如何在数据库中“还原”数据?
例如-当我的服务器关闭时,某些行保持为NEW
状态。 启动服务器时,我需要将状态更改为另一个。 首先想到的是调用@PostConstruct
的方法:
@PostConstruct
public void init() {
someService.prepareForExecution();
}
但是在我看来,这是错误的。 我还可以运行另一个将被更新的Sheduller。
但是我必须确保在服务器启动之前,所有数据都将恢复正常。 怎么做对?
我会用一个EventListener
@EventListener(ApplicationReadyEvent.class)
public void applicationReady() {
someService.prepareForExecution();
}
在此处阅读有关事件的更多信息: https : //docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-application-events-and-listeners
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.