Error log.
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 0
문제.
(서론)
프로젝트는 application-dev.yml
과 datasource-dev.yml
가 있습니다.
- application-dev.yml은 일반적으로 설정되는 script가 작성되어 있음.
- datasource-dev.yml은 datasource에서 사용할 값에 대한 명시가 되어 있음
(문제)
Spring boot와 MySQL를 연결할 때 필요한 정보가 없거나 잘못되었기 때문에 발생했습니다.
해결.
- 문제 파일에서는
spring.profiles.active=dev
가 있었습니다. 이를 지워주었습니다. spring.config.import = -classpath:/datasource-dev.yml
을 추가해주었습니다.- 빌드전, 구성편집에 진입하여 활성화된 프로파일 (Active profiles)에 dev를 넣어주었습니다.
application-dev.yml
spring:
config:
import:
- classpath:/datasource-dev.yml
datasource:
driver-class-name: ${SPRING_DATASOURCE_DEV.DRIVER}
url: ${SPRING_DATASOURCE_DEV.URL}
username: ${SPRING_DATASOURCE_DEV.USERNAME}
password: ${SPRING_DATASOURCE_DEV.PASSWORD}
jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
datasource-dev.yml
SPRING_DATASOURCE_DEV:
DRIVER: com.mysql.cj.jdbc.Driver
URL: jdbc:mysql://localhost:3306/springbootstudydb
USERNAME: root
PASSWORD: 1234