반응형
문제
Spring Initializr을 이용하여 프로젝트 생성 후, 추가설정 없이 바로 실행했더니
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-06 16:31:50.532 ERROR 20275 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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 1
이렇게 에러메세지가 출력되고, 정상실행이 되지 않았다!
이유
에러메세지를 보면, datasource configure에 실패했다는 의미인 것 같다.
application.properties를 확인해보면 아무것도 작성되어 있지 않다.
해결
application.properties
spring.datasource.url=jdbc:mysql://{localhost}/{DB_Name}
spring.datasource.username={username}
spring.datasource.password={password}
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.format_sql=true
url에는 host이름과 데이터베이스 이름을 입력해주고,
username, password도 입력해준다.
build.gradle
...
dependencies {
...
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}
...
jpa연결을 위해 build.gradle에는 dependency가 추가되어 있어야한다!
이제 실행해보면, 정상적으로 실행되는 것을 확인할 수 있다!
반응형