Iván López
Iván López

Reputation: 944

Initialize jOOQ with SpringBoot

We have a problem using jOOQ in a SpringBoot (1.3.3.RELEASE) application because it seems that jOOQ is not initialized (we don't see the ascii-art logo) until the first query is executed. This shouldn't be a problem but in our use case it is. So we're looking for a way to initialize jOOQ during the startup of the application.

What we've done is just create the following bean that is executed automatically by Spring once the application context has been created and just execute a query to initialize jOOQ.

@Bean
CommandLineRunner runner(DSLContext create) {
    new CommandLineRunner() {
        @Override
        void run(String... args) throws Exception {
            create.fetchCount(create.select(BLACKBOX))
        }
    }
}

Is there a better way to do this?

Upvotes: 3

Views: 1327

Answers (1)

Iván López
Iván López

Reputation: 944

So, as Lukas said, that's an answer:

@Bean
CommandLineRunner runner(DSLContext create) {
    new CommandLineRunner() {
        @Override
        void run(String... args) throws Exception {
            create.selectOne().fetch()
        }
    }
}

Upvotes: 4

Related Questions