/개발/5 Fixes for Spring Boot's 'url attribute is not specified' Error
DevelopmentSpring BootDataSource에러

5 Fixes for Spring Boot's 'url attribute is not specified' Error

Diagnose the five causes of Spring Boot's 'Failed to configure a DataSource: url attribute is not specified' startup error, and fix it in 5 minutes with copy-paste MySQL, PostgreSQL, and H2 configs.

5 Fixes for Spring Boot's 'url attribute is not specified' Error

Fix Spring Boot DataSource URL Errors in 5 Minutes: 5 Root Causes

CODE
***************************
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

If that red stack trace has you panicking—"the code looks fine, why won't it start?"—this post is all you need. Bottom line: this error has exactly five causes. Pick your case, copy-paste, and you're done.

What the Error Message Actually Means

When Spring Boot finds JDBC-related libraries on the classpath, it kicks off DataSourceAutoConfiguration. Here's how that auto-config works:

  1. Look for a spring.datasource.url value.
  2. If missing → try falling back to an embedded DB such as H2, HSQLDB, or Derby.
  3. If no embedded DB is on the classpath either → abort startup with "there is no DataSource I can create."

In other words, this exception is thrown only when both conditions hold: no explicit URL, and no embedded DB to fall back to. So the fix is one of two paths: "provide a URL" or "add an embedded DB."

Diagnose and Fix: 5 Causes

spring.datasource.url is missing entirely

  • Symptom: The most common case. The URL setting is completely missing from yml/properties.
  • Check: Search for the spring.datasource.url key in src/main/resources/application.yml.
  • Fix: Add the DB-specific config from the copy-paste snippets below, as-is.

② The wrong profile is active (application-prod.yml not loaded)

  • Symptom: The URL is in your local yml, but a different profile is active so that config never gets read.
  • Check: Look for this line in the boot log.
CODE
The following 1 profile is active: "prod"

If that doesn't match the profile you expected, that's your culprit.

  • Fix: Explicitly specify the intended profile.
Bash
java -jar app.jar --spring.profiles.active=prod
# 또는 환경변수
export SPRING_PROFILES_ACTIVE=prod

Also verify that the application-prod.yml filename is exact and that it actually contains a URL.

③ JDBC driver dependency is missing

  • Symptom: You did set a URL, but Failed to determine a suitable driver class appears alongside it.
  • Check: Confirm the driver actually made it onto the classpath with a command like ./gradlew dependencies | grep -i mysql.
  • Fix: Add the driver that matches your DB (see the snippets below).

Tip on the message difference: If the driver is present but the URL is missing, 'url' attribute is not specified stands out. If the URL is present but the driver is missing, Failed to determine a suitable driver class is emphasized. Use which sentence is highlighted to tell ① from ③.

④ No embedded DB such as H2

  • Symptom: You just wanted a quick test, didn't configure any DB, and didn't add H2 either.
  • Fix: For test/local use, adding H2 alone is enough—auto-fallback will start the app immediately.
GRADLE
runtimeOnly 'com.h2database:h2'

${} placeholders are not resolved

  • Symptom: You wrote ${DB_URL} in yml, but the env var is empty so an empty string gets injected.
  • Check: Verify the env var is actually set with echo $DB_URL.
  • Fix: Inject it via IntelliJ run configuration Environment variables, Docker environment:, or the JVM -DDB_URL=... option—or use default-value syntax.
YAML
spring:
  datasource:
    url: ${DB_URL:jdbc:h2:mem:testdb}
    password: ${DB_PASSWORD:}

With the ${DB_URL:default} form, even if the env var is missing it falls back to the value after the colon, so startup isn't blocked. If your team follows 12-factor config, make this default-value pattern the standard.

Copy-Paste Config Collection

MySQL (Spring Boot 3.x)

Starting with Spring Boot 3.x, the coordinates changed from mysql-connector-java to mysql-connector-j. Plenty of people get stuck copy-pasting from old posts—watch out!

build.gradle

GRADLE
runtimeOnly 'com.mysql:mysql-connector-j'

application.yml

YAML
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: ${DB_PASSWORD:root}
    driver-class-name: com.mysql.cj.jdbc.Driver

application.properties

PROPERTIES
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=root

PostgreSQL

build.gradle

GRADLE
runtimeOnly 'org.postgresql:postgresql'

application.yml

YAML
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/mydb
    username: postgres
    password: ${DB_PASSWORD:postgres}

H2 (in-memory, for tests/local)

build.gradle

GRADLE
runtimeOnly 'com.h2database:h2'

application.yml

YAML
spring:
  datasource:
    url: jdbc:h2:mem:testdb
  h2:
    console:
      enabled: true

Maven users (pom.xml)

XML
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>

runtimeOnly vs implementation

TypeExposed at compile timeUse for
implementationYesLibraries you import directly in code
runtimeOnlyNoJDBC drivers and other runtime-only deps

JDBC drivers are almost never imported in your own code, so runtimeOnly is the canonical choice. It also prevents you from accidentally hard-coding driver class names in source.

Bypass When You Don't Need a DB at All

If you're only building a web API and haven't wired up a DB yet, but this error still fires, just turn auto-config off.

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

Or via properties:

YAML
spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

⚠️ Warning: This is the right answer only when you truly won't use a DB. If you'll use even one JPA Repository, exclude is an anti-pattern that just kicks the problem down the road. In that case, put a proper URL in—H2 or a real DB.

A Note from Production Experience

For local development I almost always bring up MySQL/PostgreSQL via docker-compose.yml, and set the URL with a default-value pattern like ${DB_URL:jdbc:h2:mem:testdb}. That way a teammate who hasn't started Docker can clone and boot on H2 immediately, and once Docker is up it attaches to the real DB. That one default-value line is the cheapest way I've found to cut down on "it worked on my machine."

3-Minute Diagnostic Checklist

  1. Is the spring.datasource.url key present in yml?
  2. Does the active profile in the boot log match what you intended?
  3. Did the DB driver show up in dependencies?
  4. If this is for tests, did you add H2?
  5. Are ${} env vars actually being injected? (default-value syntax recommended)

FAQ

Q. I clearly set the URL and still get the same error. A. Almost always a profile issue. Check The following profiles are active: in the boot log. If the yml where you put the URL isn't the one that's actually active, that config is ignored.

Q. I added mysql-connector-java and it still doesn't work. A. In Spring Boot 3.x the coordinates changed to com.mysql:mysql-connector-j. The old coordinates are deprecated—switch to the new ones.

Q. How do I boot the server quickly with no DB? A. A single runtimeOnly 'com.h2database:h2' line starts you on in-memory H2 immediately. If you'll never use a DB, exclude DataSourceAutoConfiguration.class.

확인 정보
✦ ✦ ✦
편집 검토 · Editorial Review

Nodelog는 모든 콘텐츠의 내용과 출처를 공개 전에 검토합니다. 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서와 함께 확인하며, 검토 기준과 정정 원칙은 편집 정책에서 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.

편집 책임 · Nodelog 기술 편집팀·발행 · ·업데이트 ·

Comments

Be the first to comment.