LoginSignup
1
2

More than 3 years have passed since last update.

Spring Boot で Rest API 構築 その4 - MySQL への接続設定

Last updated at Posted at 2019-10-06

Outline

  • Spring Boot のアプリケーションから MySQL への接続設定を行う

元々の問題

Spring Initializr で構築したアプリケーションを起動するとエラーが発生していた
https://qiita.com/sawa-@github/items/292a665fecf212ccc38a#とりあえず起動してみる

設定

MySQL への接続情報を設定ファイルに追加する

src/main/resources/application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/rest_api?useSSL=false
    username: root
    password: root
    driverClassName: com.mysql.cj.jdbc.Driver

アプリケーションの起動

docker-compose で MySQL コンテナを起動

$ docker-compose up -d
Starting rest-api-mysql ... done

アプリケーション起動

Run ボタンを押す

190817-0005.png


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.7.RELEASE)

(省略)

2019-10-06 22:25:18.208  INFO 43050 --- [  restartedMain] c.e.s.SpringBootRestApiApplication       : Started SpringBootRestApiApplication in 4.536 seconds (JVM running for 5.495)

起動するだけの空っぽなアプリケーションだけど起動まで出来るようになりました

1
2
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
2