1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Spring Boot + Spring JDBC XAMPPのMySQLに接続する設定

Posted at

はじめに

Spring Boot + Spring JDBCを使って
ローカル環境でMySQLの疎通確認をしたかったので
XAMPPのMySQL(MariaDB)を使ってやってみました。

開発環境

  • OS: Windows 10
  • Java: 11
  • Spring Boot: 2.3.5
  • ビルドツール : Gradle
  • IDE: Eclipse 2020-12
  • MySQL(MariaDB): 10.4.14

設定ファイル

  • build.gradle

※単体テスト用ライブラリは省略しています

build.gradle
plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'eclipse'
	id 'idea'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11

compileJava.options.encoding = "UTF-8"


repositories {
	mavenCentral()
}

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'

}

  • application.yml

※application.ymlはapplication.propertiesをyml形式に書き換えたものです。
※配置場所:プロジェクト名\src\main\resources\application.yml

application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/[データベース名]
    driverClassName: com.mysql.jdbc.Driver
    username: [ユーザー名]
    password: [パスワード]

スムーズに動かすコツ

  • SpringのTomcatとMySQLのApache、両方を起動させておくこと

MySQLの起動を忘れてしまいがち...

参考

Spring公式MySqlチュートリアル

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?