Backend

[Spring Boot] Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

HUN 2021. 7. 11. 10:46

에러 상황


Spring boot application을 실행하면 아래 에러가 발생하여 서버가 동작하지 않는다.

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

 

에러 분석


datasource의 url이 특정되지 않고, 내장 datasource 설정이 없다. 따라서 데이터베이스 연결 설정을 해줘야한다. h2 데이터베이스 연결 설정하면 될 것 같다.

 

에러 해결


1. 데이터베이스 파일 생성

  • h2 웹 콘솔을 열고
    • jdbc:h2:~/[데이터베이스이름] 으로 최소 한번 접속
    • ~/[데이터베이스이름].mv.db 파일 생성 확인
    • 이후 jdbc:h2:tcp://localhost/~/[데이터베이스이름]으로 접속

 

2. build.gradle에 dependency 추가

runtimeOnly 'com.h2database:h2'

 

 

application.yml에 설정 추가

 

  • jap.hibernate.ddl-auto
    애플리케이션 실행 시점에 테이블을 drop하고 다시 생성한다.
  • jpa.properties.hibernate.format_sql: true
    sql문을 보기 좋게 출력해준다.
  • logging.level.org.hibernate.SQL: debug
    logger를 통해 하이버네이트 실행 SQL을 남긴다. 

 

 

728x90