QueryDsl 적용
build.gradle
//(1)
buildscript {
dependencies {
classpath("gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.10")
}
}
plugins {
id 'org.springframework.boot' version '2.7.2'
id 'io.spring.dependency-management' version '1.0.12.RELEASE'
id 'java'
}
//(2)
apply plugin: "com.ewerk.gradle.plugins.querydsl"
group = 'jpa'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.0'
//(3)
implementation 'com.querydsl:querydsl-jpa'
implementation 'com.querydsl:querydsl-apt'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
//(4)
def querydslDir = 'src/main/generated'
//(5)
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslSourcesDir = querydslDir
}
//(6)
sourceSets{
main{
java{
srcDirs = ['src/main/java', querydslDir]
}
}
}
//(7)
compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}
//(8)
configurations {
querydsl.extendsFrom compileClasspath
}
tasks.named('test') {
useJUnitPlatform()
}
QuerydslConfiguration.java 파일 생성
package jpa.board.configuration;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
* packageName : jpa.board.configuration
* fileName : QuerydslConfiguration
* author : 김재성
* date : 2022-08-02
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2022-08-02 김재성 최초 생성
*/
@Configuration
public class QuerydslConfiguration {
@PersistenceContext
private EntityManager entityManager;
@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
gradle task에서 compileQuerydsl 더블 클릭
프로젝트 - build - generated - qurydsl 폴더에 Q클래스 파일이 생성됨
'스프링' 카테고리의 다른 글
[Spring Boot] rememberMe 사용하여 자동 로그인 기능 개발 (0) | 2021.10.22 |
---|---|
[JPA] @valid 어노테이션을 사용하여 벨리데이션 처리하기 (0) | 2021.10.18 |
[Spring boot] 웹서비스 ec2에 배포하기 (RDS 데이터베이스 연동) (0) | 2021.10.06 |
[SPRING JPA] 쿼리 파라미터 로그 남기기 p6spy (0) | 2021.09.07 |
[Spring Boot] 7. 게시판 멀티파일 업로드, 파일 다운로드(Gradle+Mybatis+멀티프로젝트+MYSQL+STS) (1) | 2021.08.15 |