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

KIMEUNSUN·2023년 3월 16일
0


생성후 Intellij에서 최초 실행했을 때 오류 발생

Failed to configure a DataSource 에러가 발생하는 이유는 Database에 연결할 때 필요한 정보가 없기 때문

DB를 사용하지 않는 경우

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) 추가

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

}

DB를 사용하는 경우

application.properties에서 설정 추가

spring.datasource.url=jdbc:[Database]://localhost:3306/[Database스키마]
spring.datasource.username=[DB 아이디]
spring.datasource.password=[DB 비밀번호]
spring.datasource.driver-class-name=[JDBC 드라이버]

0개의 댓글