Spring Boot, Doma2, Gradle initial setting summary

At the beginning

When developing with Eclipse, I'm always addicted to the initial settings of Spring Boot + Doma2 + Gradle, so I will summarize it for myself.


Setup steps

(Optional) Create an application template with Spring Initializer



Add a dependency on Doma2


dependencies {
  // ...abridgement
  implementation 'org.seasar.doma.boot:doma-spring-boot-starter:1.4.0'
  annotationProcessor 'org.seasar.doma:doma-processor:2.35.0'

Set up Eclipse

Add plugins for Eclipse settings to plugins in build.gradle.


plugins {
  // ...abridgement
  id 'com.diffplug.eclipse.apt' version '3.23.0'

Execute gradle eclipse to reflect the settings.

$ ./gradlew eclipse
Starting a Gradle Daemon (subsequent builds will be faster)

5 actionable tasks: 5 executed

You can confirm that the Eclipse settings (annotation processing) have been completed.



Create a simple API

Follow the README of https://github.com/domaframework/doma-spring-boot/tree/1.4.0 And basically create it.

Define Entity


package com.example.demo;

import org.seasar.doma.Entity;

import lombok.Data;

public class Reservation {

	private Integer id;

	private String name;

Define Dao Interface


package com.example.demo;

import java.util.List;

import org.seasar.doma.Dao;
import org.seasar.doma.Insert;
import org.seasar.doma.Select;
import org.seasar.doma.boot.ConfigAutowireable;
import org.springframework.transaction.annotation.Transactional;

public interface ReservationDao {

	public List<Reservation> selectAll();

	public int insert(Reservation reservation);

Hover over ReservationDao # selectAll and right click> Doma> Jump to Sql File to generate an empty SQL file. (If you have added the Doma Tools plugin to Eclipse)

Write a query in a SQL file


FROM reservation

Define Service and Controller classes


package com.example.demo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

public class ReservationService {

	private ReservationDao reservationDao;

	public List<Reservation> selectAll() {
		return reservationDao.selectAll();

	public int insert(Reservation reservation) {
		return reservationDao.insert(reservation);


package com.example.demo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

public class ReservationController {

	private ReservationService reservationService;

	@GetMapping(path = "/")
	public List<Reservation> selectAll() {
		return reservationService.selectAll();

	@PostMapping(path = "/")
	public int insert(@RequestBody Reservation reservation) {
		return reservationService.insert(reservation);


Create a Reservation table at startup

We use a Java in-memory DB called HSQLDB. If you place schema.sql directly under src / main / resources, you can run the table creation script at startup.


CREATE TABLE reservation (
  id   IDENTITY,

API operation check

POST (registration)

POST http://localhost:8080 HTTP/1.1
Content-Type: application/json

  "id": 1,
  "name": "Sample A"


HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sun, 12 Jul 2020 15:09:30 GMT
Connection: close


GET (Get all)

GET http://localhost:8080 HTTP/1.1


HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sun, 12 Jul 2020 15:10:20 GMT
Connection: close

    "id": 1,
    "name": "Sample A"

(Supplement) When a DOMA4019 error occurs

If you get a DOMA4019 error that the absolute path of the SQL file is not what you expected, as shown below.

[DOMA4019] The file "META-INF/com/example/demo/ReservationDao/selectAll.sql" is not found in the classpath. The absolute path is "C:\Git\springboot-doma2-sample\bin\main\META-INF\com\example\demo\ReservationDao\selectAll.sql".

Right-click> Properties> Modify Java build path on the target project.


Project default output folder ⇒ Modified to a specific output folder (bin / main).


At the end

The created application is stored in Repository. See if you want to see the full amount of build.gradle.


Recommended Posts

Spring Boot, Doma2, Gradle initial setting summary
Spring Boot 2.2 Document Summary
Spring Boot 2 multi-project in Gradle
Spring Boot External setting priority
◆ Spring Boot + gradle environment construction memo
Database linkage with doma2 (Spring boot)
Implement Spring Boot application in Gradle
(IntelliJ + gradle) Hello World with Spring Boot
Add spring boot and gradle to eclipse
Create a website with Spring Boot + Gradle (jdk1.8.x)
Summary of what I learned about Spring Boot
Run Scala applications with Spring Boot through Gradle
Challenge Spring Boot
Build Spring Boot project by environment with Gradle
Java tips-Create a Spring Boot project in Gradle
Spring Boot Form
I wanted to gradle spring boot with multi-project
Spring Boot Memorandum
gae + spring boot
View the Gradle task in the Spring Boot project
A memorandum of addiction to Spring Boot2 x Doma2
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Learning Spring Boot [Beginning]
Spring boot memo writing (2)
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Download with Spring Boot
Execution of initial processing using Spring Boot Command Line Runner