1. Overview

This tutorial is a follow-up to the Introduction to jOOQ with Spring article, covering the ways that jOOQ can be used within a Spring Boot application.

If you have not gone through that tutorial, please take a look at it and follow the instructions in section 2 on Maven Dependencies and in section 3 on Code Generation. This will generate source code for Java classes representing tables in the sample database, including Author, Book and AuthorBook.

2. Maven Configuration

In addition to the dependencies and plugins as in the previous tutorial, several other components need to be included in the Maven POM file to make jOOQ work with Spring Boot.

2.1. Dependency Management

The most common way to make use of Spring Boot is to inherit from the spring-boot-starter-parent project by declaring it in the parent element. However, this method is not always suitable as it imposes an inheritance chain to follow, which may not be what users want in many cases.

This tutorial uses another approach: delegating the dependency management to Spring Boot. To make it happen, just adds the following dependencyManagement element to the POM file:


2.2. Dependencies

In order for Spring Boot to control jOOQ, a dependency on the spring-boot-starter-jooq artifact needs to be declared:


Note that this article focuses on the open-source distribution of jOOQ. If you want to work with the commercial distributions, check out the Guide to Using jOOQ’s Commercial Distributions with Spring Boot on the official blog.

3. Spring Boot Configuration

3.1. Initial Boot Config

Before we get to the jOOQ support, we’re going to start preparing things with Spring Boot.

First, we’re going to take advantage of the persistence support and improvements in Boot and our data access information in the standard application.properties file. That way, we can skip over defining the beans and making these configurable via a separate properties file.

We’ll add the URL and credentials here to define our embedded H2 database:


We’re also going to define a simple Boot application:

public class Application {

We’ll leave this one simple and empty and we’ll define all other bean declarations in another configuration class – InitialConfiguration.

3.2. Bean Configuration

Let’s now define this InitialConfiguration class:

public class InitialConfiguration {
    // Other declarations

Spring Boot has automatically generated and configured the dataSource bean based on properties set in the application.properties file, so we do not need to register it manually. The following code lets the auto-configured DataSource bean to be injected into a field, and shows how this bean is used:

private DataSource dataSource;

public DataSourceConnectionProvider connectionProvider() {
    return new DataSourceConnectionProvider
      (new TransactionAwareDataSourceProxy(dataSource));

Since a bean named transactionManager has also been automatically created and configured by Spring Boot, we do not need to declare any other bean of the DataSourceTransactionManager type as in the previous tutorial to take advantage of Spring transaction support.

A DSLContext bean is created in the same way as in the PersistenceContext class of the preceding tutorial:

public DefaultDSLContext dsl() {
    return new DefaultDSLContext(configuration());

Lastly, a Configuration implementation needs to be provided to DSLContext. Since Spring Boot is able to recognize the SQL dialect in use through the existence of H2 artifact on the classpath, a dialect configuration is no longer necessary:

public DefaultConfiguration configuration() {
    DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
      .set(new DefaultExecuteListenerProvider(exceptionTransformer()));

    return jooqConfiguration;

4. Using Spring Boot With jOOQ

To make the demonstration of Spring Boot support for jOOQ easier to be followed, the test cases in the prequel of this tutorial are reused with a little change to its class-level annotations:

public class SpringBootTest {
    // Other declarations

It is clear that rather than adopting the @ContextConfiguration annotation, Spring Boot uses @SpringApplicationConfiguration to take advantage of SpringApplicationContextLoader context loader to test applications.

Test methods for inserting, updating and deleting data are exactly the same as in the previous tutorial. Please have a look at section 5 of that article on Using jOOQ with Spring for more information. All the tests should be successfully executed with the new configuration, proving that jOOQ is fully supported by Spring Boot.

5. Conclusion

This tutorial dug deeper into the use of jOOQ with Spring. It introduced the ways for a Spring Boot application to take advantage of jOOQ to interact with a database in a type-safe manner.

The implementation of all these examples and code snippets can be found in a GitHub project.