How to customise a jOOQ Configuration that is injected using Spring Boot

Starting from Spring Boot 2.5, there’s a handy new callback that you can implement, called DefaultConfigurationCustomizer, where the word DefaultConfiguration corresponds to jOOQ’s DefaultConfiguration. You can simply create a class like this in your project:

import org.jooq.conf.RenderQuotedNames;
import org.jooq.impl.DefaultConfiguration;
import org.springframework.boot.autoconfigure.jooq.*;
import org.springframework.context.annotation.*;

public class Config {
	public DefaultConfigurationCustomizer configurationCustomiser() {
		return (DefaultConfiguration c) -> c.settings()

The above callback receives the DefaultConfiguration at its initialisation stage, during which you can still safely mutate it to change any of the defaults, or add additional settings, etc. That’s it!

You can set a breakpoint inside of the lambda to validate when this initialisation is invoked:

Caused by: java.lang.RuntimeException
	at org.jooq.example.spring.Config.lambda$0(
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.lambda$jooqConfiguration$1(
	at java.base/$ForEachOp$OfRef.accept(
	at java.base/java.util.ArrayList.forEach(
	at java.base/$RefSortingSink.end(
	at java.base/$ChainedReference.end(
	at java.base/$ChainedReference.end(
	at java.base/
	at java.base/
	at java.base/$ForEachOp.evaluateSequential(
	at java.base/$ForEachOp$OfRef.evaluateSequential(
	at java.base/
	at java.base/
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.jooqConfiguration(
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.base/java.lang.reflect.Method.invoke(
	... 119 more

To play around with this example, check out our jOOQ-spring-boot-example on github.

2 thoughts on “How to customise a jOOQ Configuration that is injected using Spring Boot

  1. If you’re using R2DBC, take note that `JooqAutoConfiguration` only works with a traditional `javax.sql.DataSource`, not a `io.r2dbc.spi.ConnectionFactory`. Worse, if you have both available (e.g. for Flyway, which still does not yet support R2DBC), make sure that the `DSLContext` that you’re using is actually the reactive one, not this one that Spring slips between your beans. Ask me how I know :-/

Leave a Reply