개발/Spring
[JPA] SpringBoot JPA 프로젝트 설정
윤호
2021. 9. 6. 11:05
프로젝트 환경설정
프로젝트 생성
- spring initializer 에서 프로젝트 생성
- 의존성
- web, thymeleaf, jpa, h2, lombok
라이브러리 살펴보기
- gradle -> dependencies 에서 확인할 수 있음
뷰 환경 설정
- spring-boot-devtools 의존
- 화면 개발할 때 서버를 재부팅하지 않아도 화면 수정사항이 반영됨.
- build - recompile ~.html 해당 페이지만 리컴파일하면 수정 사항이 보임
데이터베이스 설정
- h2 데이터베이스 설치 후 bin/h2.sh 로 실행
- 최초 실행시
jdbc:h2:~/jpashop
으로 연결 (~/jpashop.mv.db 파일 생성) - 이후
jdbc:h2:tcp://localhost/~/jpashop
으로 연결
- 최초 실행시
- appliation.yml 파일 생성 및 설정
spring:
datasource:
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
# show_sql: true
format_sql: true
logging:
level:
org.hibernate.SQL: debug
org.hibernate.type: true
쿼리 파라미터 찍기
- application.yml 에서 hibernate.type: trace 추가
- implementation
'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'
테스트
- tip)
- intellij - template - custom 에서 tdd 만들기
- 옵션 커멘드 V : 메소드에서 반환값 뽑아오는거
- 엔티티 메니저 메소드는 트랜잭션에서 사용되야한다.
- @Transactional
- @Rollback(false) : 테스트 후 데이터베이스를 롤백하지 않음