Search
Duplicate

[스프링 게시판] 프로젝트 생성 및 세팅

@3/7/2023

프로젝트 생성

자바 8, 11 차이

영한님은 자바 11을 권장하지만, 스프링에서 자바 11을 써야하는 정확한 이유를 찾지는 못했음. 일단 8로 돌려보며 추후에 문제가 생기는 지 확인해보고 싶어서 8로 선택.
@3/11/2023 optional isEmpty 11부터 사용 가능(스프링 관련 부분은 아니지만)
참고로 스프링 부트 3.0부터는 자바 17을 사용해야 함(출처)

Project setting

Dependencies

Thymeleaf
Spring Web
MySQL Driver
Spring Data JPA
Lombok
Spring Boot DevTools

패키지 구조

 계층형 방식
domain
repository
service
controller
개념적 방식 (Spring petclinic 예제)
model
owner
system
vet
 역사와 전통이 있는 계층형 방식 선택

설정 → Annotation processing 체크

Test run

ForumApplication.java 실행 시 DB 오류 발생
MySQL db 설정을 안 해서 발생하는 것이었음(..)

MySQL DB 생성 및 권한 부여

DB 생성
mysql> create database springforumdb;
SQL
복사
유저 생성 및 권한 부여
mysql> create user 'springforumuser'@'%' identified by '1234'; mysql> grant all on springforumdb.* to 'springforumuser'@'%'; mysql> flush privileges;
SQL
복사
로그인 명령어
$ mysql -hlocalhost -uspringforumuser -p springforumdb
Shell
복사

application.yml 설정

spring: datasource: url: jdbc:mysql://localhost:3306/springforumdb username: springforumuser password: driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: create properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect #show-sql: true format_sql: true
Shell
복사
MySQL8Dialect는 deprecated되었다고 함(링크)

Test Run

localhost:8080
Shell
복사

MySQL workbench에 커넥션 추가

Test Connection