I have a Spring context event listener, that I use to run some initializing code for some services. That code needs a transactional context so it is not possible to run it in a @PostConstruct method.
The problem is that when the onApplicationEvent method is executed, Liquibase has not yet been executed, and the (in-memory) database is empty.
Is there a way to force the execution of Liquibase earlier in the Spring life cycle ?
Here is the code of my listener:
@Component
public class Initializer implements ApplicationListener<ContextRefreshedEvent> {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private QueuesRegistry queuesRegistry;
private TicketNumberGeneratorRegistry ticketNumberGeneratorRegistry;
public Initializer(QueuesRegistry queuesRegistry, TicketNumberGeneratorRegistry ticketNumberGeneratorRegistry) {
this.queuesRegistry = queuesRegistry;
this.ticketNumberGeneratorRegistry = ticketNumberGeneratorRegistry;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
logger.info("The application has started. Now initializing the state of some components...");
queuesRegistry.initialize();
ticketNumberGeneratorRegistry.initialize();
}
}
I have a Spring context event listener, that I use to run some initializing code for some services. That code needs a transactional context so it is not possible to run it in a
@PostConstruct
method.The problem is that when the
onApplicationEvent
method is executed, Liquibase has not yet been executed, and the (in-memory) database is empty.Is there a way to force the execution of Liquibase earlier in the Spring life cycle ?
Here is the code of my listener: