Help us understand the problem. What is going on with this article?

Spring Bootで設定のプロファイル分けをする

More than 5 years have passed since last update.

Spring Bootは、設定をapplication.propertiesやapplication.ymlで書ける。
Webの情報だと、propertiesでの設定例が多くて、YAMLの設定例が少ない印象。
基本一緒なんだけど、YAMLでの設定例を書いておく。

# spring.profiles.activeにデフォルトでアクティブなプロファイルを指定
spring:
  profiles:
    active: dev

# "---"でプロファイルを区切る
# プロファイル名はspring.profilesに書く
---
spring:
  profiles: dev
  datasource:
    url: jdbc:mysql://localhost/devdb
    username: db_user
    password: db_password
    driverClassName: com.mysql.jdbc.Driver
---
spring:
  profiles: production
  datasource:
    url: jdbc:mysql://production.com:3306/productdb
    username: db_user
    password: db_password
    driverClassName: com.mysql.jdbc.Driver

こうすると、devプロファイルで動作するようにjarが作られる。
実行時にproduction環境で動作させるには、以下のコマンドで実行する。

java -jar -Dspring.profiles.active=production hoge.jar
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away