0

How can I "restore" data in DB after start Spring boot?

For example - when my server shutdown, some rows remain in NEW status. I need change status to another, when start server. The first thing that comes to mind is to call the method in @PostConstruct:

@PostConstruct
public void init() {
   someService.prepareForExecution();
}

But it seems to me wrong. I can also run another Sheduller which will be updated.

But I must be sure that before the server starts up, all data will be restored to normal. how to do it right?

1
  • "some rows" is very unclear to me Commented Feb 6, 2019 at 12:43

1 Answer 1

2

I would use an EventListener

@EventListener(ApplicationReadyEvent.class)
public void applicationReady() {
     someService.prepareForExecution();
}

Read more about the Events here: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-application-events-and-listeners

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.