220806 springboot h2-database 사용법, 개인 정보 관련 설정

Jongleee·2022년 8월 6일
1

TIL

목록 보기
21/683

springboot h2-database 사용법

# sql 보기
spring.jpa.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

# h2 연동
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:springcoredb;MODE=MYSQL
spring.datasource.username=sa
spring.datasource.password=

#jpa hibernate 실행 시 적용 할 mysql
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

# table h2 최신화
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true

# mysql 중복 되면 서버가 죽음 해결용
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
  • 마지막 부분은 데이터베이스의 키워드 또는 예약어를 엔티티 클래스에 사용할때의 이슈를 해결해주는 용도
  • 엔티티 클래스의 이름과 컬럼이 백틱(`)으로 감싸져서 실행되기 때문

개인 정보 관련 설정

@Value("${iamSecretKey}")
    private String iamSecretKey;

의 형태로 클래스 내에서 받아올 수 있도록 설정한 후 application.properties파일에 해당 값을 저장함

application.properties파일을 gitignore등으로 추적 중지 설정해야 함

0개의 댓글