Skip to content

Commit

Permalink
✨ JDBC & JPA & QueryDsl Configuration 설정 (#7)
Browse files Browse the repository at this point in the history
* chore: mysql & jpa & queryDsl gradle 의존성 추가

* chore: queryDsl generated 디렉토리 git 추적 제거

* chore: jdbc, jpa application.yml 설정 추가

* chore: extenal-api 모듈 application.yml 그룹 추가

* chore: jpa 설정 profile 분리 && profile 그룹 추가

* chore: infra 모듈 application.yml 그룹 추가

* feat: Jpa config

* feat: QueryDsl config

* chore: EnalbeJpaAuditing auditorAwareRef 설정 제거

* fix: config 디렉토리 수정
  • Loading branch information
psychology50 authored Mar 18, 2024
1 parent 419521e commit a27a3d9
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pennyway-app-external-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
spring:
profiles:
group:
local: common, domain, infra
prod: common, domain, infra

jwt:
secret-key:
access-token: ${JWT_ACCESS_SECRET_KEY}
Expand Down
2 changes: 2 additions & 0 deletions pennyway-domain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

./main/generated/*

### NetBeans ###
/nbproject/private/
/nbbuild/
Expand Down
30 changes: 30 additions & 0 deletions pennyway-domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,34 @@ jar {enabled = true}
dependencies {
implementation project(':pennyway-common')

/* MySQL */
implementation group: 'com.mysql', name: 'mysql-connector-j', version: '8.3.0'

/* JPA */
api group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '3.2.3'

/* QueryDsl */
implementation 'com.querydsl:querydsl-core:5.0.0'
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api:2.1.1"
annotationProcessor "jakarta.persistence:jakarta.persistence-api:3.1.0"
}

def querydslDir = 'src/main/generated'

sourceSets {
main.java.srcDirs += [querydslDir]
}

configurations {
querydsl.extendsFrom compileClasspath
}

tasks.withType(JavaCompile).configureEach {
options.getGeneratedSourceOutputDirectory().set(file(querydslDir))
}

clean.doLast {
file(querydslDir).deleteDir()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package kr.co.pennyway;

public interface DomainPackageLocation {
}
14 changes: 14 additions & 0 deletions pennyway-domain/src/main/java/kr/co/pennyway/config/JpaConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kr.co.pennyway.config;

import kr.co.pennyway.DomainPackageLocation;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@EnableJpaAuditing
@EntityScan(basePackageClasses = DomainPackageLocation.class)
@EnableJpaRepositories(basePackageClasses = DomainPackageLocation.class)
public class JpaConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.co.pennyway.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueryDslConfig {
@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
42 changes: 41 additions & 1 deletion pennyway-domain/src/main/resources/application-domain.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
spring:
profiles:
group:
local: common
prod: common

datasource:
url: ${DB_URL}
username: ${DB_USER_NAME}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver

---
spring:
config:
activate:
on-profile: local

jpa:
database: MySQL
open-in-view: false
generate-ddl: false
hibernate:
ddl-auto: none
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect

logging:
level:
org.hibernate.sql: debug
org.hibernate.type: trace
com.zaxxer.hikari.HikariConfig: DEBUG

---
spring:
config:
activate:
on-profile: prod
on-profile: prod

jpa:
database: MySQL
open-in-view: false
generate-ddl: false
hibernate:
ddl-auto: none
show-sql: false
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
6 changes: 6 additions & 0 deletions pennyway-infra/src/main/resources/application-infra.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
spring:
profiles:
group:
local: common
prod: common

---
spring:
config:
Expand Down

0 comments on commit a27a3d9

Please sign in to comment.