[JAVA] A memorandum of addiction to Spring Boot2 x Doma2

About this page

I was a little addicted to developing with Spring Boot2 x Doma2, so I will leave it as a memorandum.

Our specs

Spring Boot 2.1.7 Java11 IntelliJ 2018.3 DOMA doma-spring-boot-starter:1.1.1 MySQL 5.7 gradle 5.4.1

[DOMA4019] SQL file not found in classpath

This error may occur even if the SQL file has the correct directory structure as shown below.

Example) --The location of the SQL file is correct UserRepostory findOne method src/main/xxx/domain/repository/UserResotiory.java src/main/resources/META-INF/xxx/domain/repository/UserResotiory/findOne.sql

solution)

Add the following to build.gradle

processResources.destinationDir = compileJava.destinationDir
compileJava.dependsOn processResources

Reference: https://github.com/domaframework/simple-boilerplate/blob/master/build.gradle

I get angry if I don't implement the Repository (Dao) interface at build time

The following error required a bean of type xxxxxRepository that could not be found. Consider defining a bean of type xxxxxx

solution)

  1. It is assumed that the following settings are made in IntellJ (it should be done if Lombok is installed) In Preference> Build, Execution, Deployment> Annotation Processors Turn on Enable annotation processing

  2. Annotate the Repository (Dao) interface with ConfigAutowireable

How to make DomaConfig

If you want to pass through even if there is an unknown column, you need to create Doma's Config class and override UnknownColumnHandler. (There should be other cases where Config is required) In the official document, the method of using SingletonConfig is at the top, but in the case of Spring Boot, an advanced method that matches the framework is required.

Solution example)

DomaConfig.java


@Configuration
public class DomaConfig implements Config {


    @Autowired
    private DomaAutoConfiguration domaAutoConfiguration;

    @Autowired
    private DataSource dataSource;

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }

    @Override
    public UnknownColumnHandler getUnknownColumnHandler() {
        return new UnknownColumnHandler() {
            @Override
            public void handle(Query query, EntityType<?> entityType, String unknownColumnName) {
                //Override and crush
            }
        };
    }

    @Override
    public Dialect getDialect() {
        return domaAutoConfiguration.dialect();
    }

    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource(DataSourceProperties properties) {
        return properties.initializeDataSourceBuilder().build();
    }
}

Remarks

I think MyBatis is common for Spring Boot 2 ORM, but I tried using Doma2 for the following reasons.

  1. I want to separate Java and SQL
  2. You don't have to write XML

Recommended Posts

A memorandum of addiction to Spring Boot2 x Doma2
WebMvcConfigurer Memorandum of Understanding for Spring Boot 2.0 (Spring 5)
Spring Boot Memorandum
The story of raising Spring Boot 1.5 series to 2.1 series
How to add a classpath in Spring Boot
[Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.
I tried to clone a web application full of bugs with Spring Boot
How to write a unit test for Spring Boot 2
05. I tried to stub the source of Spring Boot
How to create a Spring Boot project in IntelliJ
I tried to reduce the capacity of Spring Boot
[Spring Boot] How to create a project (for beginners)
[Introduction to Spring Boot] Submit a form using thymeleaf
How to use CommandLineRunner in Spring Batch of Spring Boot
A memorandum when creating a REST service with Spring Boot
How to boot by environment with Spring Boot of Maven
Try Spring Boot from 0 to 100.
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Introduction to Spring Boot Part 1
The story of raising Spring Boot from 1.5 series to 2.1 series part2
About the function of Spring Boot due to different versions
A story packed with the basics of Spring Boot (solved)
Extract SQL to property file with jdbcTemplate of spring boot
Spring Boot 2.x context path settings
Introduction to Spring Boot x OpenAPI ~ OpenAPI made with Generation gap pattern ~
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Get a proxy instance of the component itself in Spring Boot
Cassandra x Spring Boot struggle record
How to set Spring Boot + PostgreSQL
Going out of message (Spring boot)
A memorandum of the FizzBuzz problem
Sample code to unit test a Spring Boot controller with MockMvc
[Spring Boot] Role of each class
A memorandum of personal phpenv install
How to use ModelMapper (Spring boot)
Upgrade spring boot from 1.5 series to 2.0 series
A memo that touched Spring Boot
I want to control the default error message of Spring Boot
How to read Body of Request multiple times with Spring Boot + Spring Security
Procedure to make the value of the property file visible in Spring Boot
Java beginner tried to make a simple web application using Spring Boot
Personal memo Features of Spring Boot (mainly from a DI point of view)
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
Steps to create a simple camel app using Apache Camel Spring Boot starters
A memorandum on how to use Eclipse
What is a Spring Boot .original file?
Local file download memorandum in Spring Boot
Story when moving from Spring Boot 1.5 to 2.1
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Summary of going to JJUG CCC 2019 Spring
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
Spring Boot, Doma2, Gradle initial setting summary
Ability to display a list of products
How to split Spring Boot message file
Use cache with EhCashe 2.x with Spring Boot
Add spring boot and gradle to eclipse
Introducing the Spring Boot Actuator, a function that makes the operation of Spring Boot applications easier.
03. I sent a request from Spring Boot to the zip code search API
Sign in to a Spring Boot web application on the Microsoft ID platform
[Spring Boot] How to get properties dynamically from a string contained in a URL