I was a little addicted to developing with Spring Boot2 x Doma2, so I will leave it as a memorandum.
Spring Boot 2.1.7 Java11 IntelliJ 2018.3 DOMA doma-spring-boot-starter:1.1.1 MySQL 5.7 gradle 5.4.1
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
Add the following to build.gradle
processResources.destinationDir = compileJava.destinationDir
compileJava.dependsOn processResources
Reference: https://github.com/domaframework/simple-boilerplate/blob/master/build.gradle
The following error required a bean of type xxxxxRepository that could not be found. Consider defining a bean of type xxxxxx
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
Annotate the Repository (Dao) interface with ConfigAutowireable
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.
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();
}
}
I think MyBatis is common for Spring Boot 2 ORM, but I tried using Doma2 for the following reasons.
Recommended Posts