0

I am Trying to update DB Schema whenever application version updated. Some People said It is not a good Function but I wanna try whether I use it or not.

I Succeed Update schema when application booted.

but I have to change the timing that schema updated. and It is between after Bean object DI finished and before @PostConstruct work.

is it impossible, just before @PostConstruct work whether DI is finished or not.

how can I do this?

PS. I have known flyway work similar function compared I am making. but I want to make similar thing by my self.

Minsik Park
  • 557
  • 3
  • 9
  • 22
  • 1
    I would use [liquibase](http://www.liquibase.org/documentation/spring.html) take a look at this [answer](https://stackoverflow.com/questions/41491234/configure-datasource-for-liquibase-in-spring-boot) – Essex Boy Nov 08 '18 at 07:46

1 Answers1

0

When spring bean gets initialized, spring guarantees that all the properties will be injected (by means of applying constructor injection, setter injection or field injection)

So First of all spring calls bean's constructor Then (if the fields are not set yet) it tries to inject fields And only after that, it calls @PostConstruct

So you should be able to access the database from the post-construct method of the bean.

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97