[QueryDSL 세팅 및 전체 구조 세팅]
This commit is contained in:
30
build.gradle
30
build.gradle
@@ -23,6 +23,12 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
queryDslVersion = "5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// 개발용 의존성 추가
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
@@ -34,9 +40,31 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
|
||||
|
||||
// querydsl
|
||||
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta"
|
||||
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta"
|
||||
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
|
||||
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
|
||||
// p6spy
|
||||
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// querydsl
|
||||
def querydslDir = "$buildDir/generated/querydsl"
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += [ querydslDir ]
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
|
||||
}
|
||||
|
||||
clean.doLast {
|
||||
file(querydslDir).deleteDir()
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package com.qsl.qsl_tutorial.base;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RepositoryLoggingAspect {
|
||||
@Around("execution(* org.springframework.data.repository.Repository+.*(..))")
|
||||
public Object logQueryCall(ProceedingJoinPoint pjp) throws Throwable {
|
||||
long t0 = System.currentTimeMillis();
|
||||
String type = pjp.getSignature().getDeclaringTypeName();
|
||||
String method = pjp.getSignature().getName();
|
||||
Object[] args = pjp.getArgs();
|
||||
|
||||
log.info("[QUERY CALL] {}.{}(args={})", type, method, java.util.Arrays.toString(args));
|
||||
try {
|
||||
Object result = pjp.proceed();
|
||||
log.info("[QUERY DONE] {}.{}() in {}ms", type, method, (System.currentTimeMillis() - t0));
|
||||
return result;
|
||||
} catch (Throwable ex) {
|
||||
log.warn("[QUERY FAIL] {}.{}() -> {}", type, method, ex.toString());
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.qsl.qsl_tutorial.base;
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
@Bean
|
||||
public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
|
||||
return new JPAQueryFactory(entityManager);
|
||||
}
|
||||
}
|
@@ -9,9 +9,9 @@ spring.devtools.restart.additional-paths=src/main/java
|
||||
|
||||
# 데이터베이스 연결 정보
|
||||
# URL 형식: jdbc:postgresql://[호스트명]:[포트번호]/[데이터베이스명]
|
||||
spring.datasource.url=jdbc:postgresql://stam.kr:15432/mms
|
||||
spring.datasource.username=mms_user
|
||||
spring.datasource.password=tam1201
|
||||
spring.datasource.url=jdbc:postgresql://stam.kr:15432/imas
|
||||
spring.datasource.username=imas_user
|
||||
spring.datasource.password=stam1201
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
|
||||
# JPA/Hibernate 설정
|
||||
@@ -21,13 +21,26 @@ spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
# - update: 엔티티 변경 시 스키마 업데이트 (개발용)
|
||||
# - validate: 엔티티와 스키마 일치 여부만 검증 (운영용)
|
||||
# - none: 아무 작업도 하지 않음
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
|
||||
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=ddl/schema.sql
|
||||
spring.jpa.properties.hibernate.hbm2ddl.schema-generation.script.append=false
|
||||
|
||||
# SQL 쿼리를 콘솔에 표시
|
||||
spring.jpa.show-sql=true
|
||||
|
||||
# Hibernate가 SQL을 포맷하여 보여줌
|
||||
# Hibernate log
|
||||
spring.jpa.show-sql=false
|
||||
spring.jpa.properties.hibernate.format_sql=true
|
||||
spring.jpa.properties.hibernate.highlight_sql=true
|
||||
spring.jpa.properties.hibernate.use_sql_comments=false
|
||||
logging.level.org.hibernate.SQL=DEBUG
|
||||
logging.level.org.hibernate.orm.jdbc.bind=TRACE
|
||||
logging.level.org.springframework.data.jpa=DEBUG
|
||||
|
||||
# P6Spy
|
||||
decorator.datasource.p6spy.enable-logging=true
|
||||
decorator.datasource.p6spy.log-format=%(sqlSingleLine)
|
||||
|
||||
# CONSOLE
|
||||
spring.output.ansi.enabled=always
|
||||
|
||||
# HikariCP 연결 풀 크기 설정 (선택사항)
|
||||
# spring.datasource.hikari.maximum-pool-size=10
|
||||
|
Reference in New Issue
Block a user