plugins {
id 'java'
id 'org.springframework.boot' version '3.2.10'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.tenco'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-mustache'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.named('test') {
useJUnitPlatform()
}
패키지 설정 MVC , DDD 에 대한 개념 공부 하세요!
application.yml
spring:
profiles:
active:
- dev #활성화할 프로필 설정
application-dev.yml
server:
servlet:
encoding:
charset: utf-8
force: true
port: 8080
spring:
mustache:
servlet:
expose-session-attributes: true # Mustache 템플릿에서 세션 속성에 접근할 수 있도록 허용
expose-request-attributes: true # Mustache 템플릿에서 요청 속성에 접근할 수 있도록 허용
datasource:
driver-class-name: org.h2.Driver # 데이터베이스 드라이버로 H2 DB를 사용
url: jdbc:h2:mem:test;MODE=MySQL # H2 인메모리 데이터베이스를 MySQL 호환 모드로 사용 (테스트용)
username: sa # 데이터베이스 연결 시 기본 사용자 이름
password: # 데이터베이스 기본 비밀번호 (비어 있음)
h2:
console:
enabled: true # H2 데이터베이스 콘솔을 활성화하여 브라우저에서 데이터베이스를 관리할 수 있도록 함
sql:
init:
data-locations:
- classpath:db/data.sql # 애플리케이션 초기화 시 실행할 데이터 삽입 SQL 파일의 경로 (data.sql)
jpa:
hibernate:
ddl-auto: create # 애플리케이션이 시작될 때 데이터베이스 테이블을 자동으로 생성
show-sql: true # Hibernate가 실행하는 SQL 쿼리를 콘솔에 출력
properties:
hibernate:
format_sql: true # 출력되는 SQL 쿼리를 포맷팅하여 읽기 쉽게 출력
defer-datasource-initialization: true # 데이터베이스 초기화가 지연되도록 설정하여 JPA 설정 후에 데이터 초기화
output:
ansi:
enabled: always # 콘솔 출력 시 ANSI 색상을 항상 사용하도록 설정 (색상을 통해 로그를 더 쉽게 구분 가능)
db에서 data.sql
insert into board_tb(title, content, created_at) values('제목1','내용1',now());
insert into board_tb(title, content, created_at) values('제목2','내용2',now());
insert into board_tb(title, content, created_at) values('제목3','내용3',now());
insert into board_tb(title, content, created_at) values('제목4','내용4',now());