i want to execute some code during (or rather at the end of) application startup. I found a couple of resources doing this using @PostConstruct annotation, @EventListener(ContextRefreshedEvent.class), implementing InitializingBean, implementing ApplicationListener... All of them execute my code at startup, but the placeholder of the application properties are not replaced at that moment. So if my class has a member with an @Value("${my.property}") annotation, it returns "${my.property}" instead of the actual value defined in the yaml (or wherever). How do i accomplish to execute my code after the replacement took place?
You can implement InitializingBean
which has a method named afterPropertiesSet()
. This method will be called after all properties placeholders are replaced.