Skip to main content

Create a Project

Create a Spring Boot Project

Use https://start.spring.io/ to create a Spring Boot project. You need to choose your preferred language - Java or Kotlin.

The choice of language is important because Jimmer supports two different sets of APIs.

  • Java API - Ensures maximum developer usage

  • Kotlin API - APIs designed specifically for Kotlin to optimize the development experience

Add Dependencies

Jimmer itself is highly neutral and can be used without Spring Boot. But it also provides great integration with Spring Boot.

Users can choose to use it with or without Spring Boot. Different choices require adding different dependencies.

  • groupId: org.babyfish.jimmer

  • artifactId:

    Integrate with Spring BootStandalone Usage
    Javajimmer-spring-boot-starterjimmer-sql
    Kotlinjimmer-sql-kotlin

Compared to standalone usage, integrating with Spring Boot is simpler. So this tutorial will demonstrate the jimmer-spring-boot-starter.

Modify build.gradle or pom.xml to add dependencies:

pom.xml
<properties>
<jimmer.version>0.8.150</jimmer.version>
</properties>

<dependencies>
<dependency>
<groupId>org.babyfish.jimmer</groupId>
<artifactId>jimmer-spring-boot-starter</artifactId>
<version>${jimmer.version}</version>
</dependency>
...other dependencies omitted...
</dependencies>
info

If you are using Gradle as your build tool, you can also use third-party Gradle plugin tech.argonariod.gradle-plugin-jimmer provided by the community to automatically identify the project type and add dependencies automatically.

The tech.argonariod.gradle-plugin-jimmer gradle plugin is community-provided and maintained to simplify Jimmer project configuration, and it is not officially maintained by Jimmer.

Repository URL: https://github.com/ArgonarioD/gradle-plugin-jimmer

Additional Configuration Needed for Kotlin

If using Kotlin, you must modify the Spring Boot configuration file - this is very important.

warning

Kotlin projects must configure jimmer.language

jimmer.language = kotlin

Other Useful Configurations

In addition to the required jimmer.language for Kotlin projects, there are other useful configurations.

Here are a few basic configurations that work for both Java and Kotlin:

PropertyTypeDefaultDescription
jimmer.dialectstringorg.babyfish.jimmer.sql.dialect.DefaultDialectDatabase dialect class name
jimmer.show-sqlbooleanfalsePrint executed SQL if true
jimmer.pretty-sqlbooleanfalseEnsure that the printed SQL is well-formatted (compact by default)
jimmer.database-validation-modeNONE|WARNING|ERRORNONEValidate consistency between database schema and entity types. WARNING logs inconsistencies, ERROR throws errors.

See Spring/Appendix for complete documentation on configurations.

jimmer.dialect = org.babyfish.jimmer.sql.dialect.MySqlDialect  
jimmer.show-sql = true
jimmer.pretty-sql = true
jimmer.database-validation-mode = ERROR
...other configurations omitted...

Add Other Required Dependencies

In addition to Jimmer, some other dependencies are required like spring-web, JDBC driver, etc.

Modify build.gradle or pom.xml to add dependencies:

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<scope>runtime</scope>
</dependency>

...other dependencies omitted...
</dependencies>