Error

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

luminous13 2022. 11. 15. 15:44

문제

스프링부트 처음 실행 시 마주친 문제

JPA를 의존성에 추가했는데 JPA를 사용하려면 기본적으로 DB를 연결해야된다.

설정 파일에 (.properties, .yml(yaml)) 연결할 DB에 대한 정보가 없어서 발생한 문제다.

 

해결

다음과 같이 설정 파일에 DB 정보를 입력해준다.

spring.datasource.url=jdbc:mysql://localhost:3306/test?autoReconnect=true
spring.datasource.username=root
spring.datasource.password=0000
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

jdbc:mysql://호스트명:포트번호/DB명?autoReconnect=true

url은 DB 위치를 명시하고, usernamed은 db 사용자이름을 입력한다.

마지막으로 드라이버명을 명시하는데 사실 마지막 줄은 적지 않아도 된다. 스프링부트에서 url을 추론하여 driver을 설정할 수 있기 때문이다.