[初心-Spring Boot] 게시판 제작 - 1. project 생성

0

초심-spring boot

목록 보기
13/16

1. Spring-boot Project 생성



생성 방법은 여기 참조!

2. build.gradle 설정


plugins {
	id 'org.springframework.boot' version '2.5.2'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
}

group = 'com.rptp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	runtimeOnly 'mysql:mysql-connector-java'
}

test {
	useJUnitPlatform()
}

DB는 Mysql을 사용할 예정이다. 왜 싸지방에서는 H2가 안깔리는거야 ㅠㅠ

3. application.properties 수정


spring.datasource.url=jdbc:mysql://localhost:3306/board?serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

db에 관한 설정들이다.

spring.datasource.url

DB의 연결주소를 작성하면 된다. mysql에서 schema를 생성하고 {board} 부분을 지운 후 생성한 스키마명을 넣으면 된다.

username & password

DB사용자의 이름과 비밀번호를 입력하면 된다.

spring.jpa.show-sql

jpa가 실행될 때 sql쿼리를 콘솔에 출력하는지 여부이다

spring.jpa.hibernate.ddl-auto

sql문 중 DDL(Data Definition Language)문 생성 옵션이다.

  • none: 아무것도 실행하지 않는다 (대부분의 DB에서 기본값이다)
  • create-drop: SessionFactory가 시작될 때 drop및 생성을 실행하고, SessionFactory가 종료될 때 drop을 실행한다 (in-memory DB의 경우 기본값이다)
  • create: SessionFactory가 시작될 때 데이터베이스 drop을 실행하고 생성된 DDL을 실행한다
  • update: 변경된 스키마를 적용한다
  • validate: 변경된 스키마가 있다면 변경점을 출력하고 애플리케이션을 종료한다

참조


https://pravusid.kr/java/2018/10/10/spring-database-initialization.html

0개의 댓글