Date:

Share:

How to customise a jOOQ Configuration that is injected using Spring Boot – Java, SQL and jOOQ.

Related Articles

Starting with Spring Boot 2.5, there is a reusable and useful connection that you can implement, called DefaultConfigurationCustomizer, Where the word DefaultConfiguration corresponds to that of jOOQ DefaultConfiguration. You can simply create such a class in your project:

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

@Configuration
public class Config 
	@Bean
	public DefaultConfigurationCustomizer configurationCustomiser() 
		return (DefaultConfiguration c) -> c.settings()
			.withRenderQuotedNames(
				RenderQuotedNames.EXPLICIT_DEFAULT_UNQUOTED
			);
	

The call back up gets the DefaultConfiguration In its initialization phase, during which you can still perform a safe mutation to change any of the defaults, or add additional settings, etc. This!

You can set a breakpoint within the lambda to verify when this boot is enabled:

Caused by: java.lang.RuntimeException
	at org.jooq.example.spring.Config.lambda$0(Config.java:30)
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.lambda$jooqConfiguration$1(JooqAutoConfiguration.java:104)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration$DslContextConfiguration.jooqConfiguration(JooqAutoConfiguration.java:104)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 119 more

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

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles