LoginSignup
0
1

More than 3 years have passed since last update.

Spring Boot / Spring Framework よく使うメモ

Posted at

1.application.properties

application.properties
server.port = 18080

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.ore.ore.package=ERROR

spring.datasource.url=${DB_URL}

1.1 server.port

Spring BootにはCommon Application propertiesというプロパティファイルがあり、デフォルト値を持つものがある。

例えば、server.portは8080がデフォルトだが、ポートが衝突する場合は別のポートを指定する必要がある。

プロパティファイルに何も記述が無い場合は、server.port = 8080が指定されているのと同じ状態である。

1.2 logging.level

logging.level.*
の*部分をパッケージ名に変更することで、パッケージ単位でログ出力のレベルを変更できる。

1.3 環境変数を使う

spring.datasource.url=${DB_URL}
といった形で${環境変数名}をプロパティファイルに記載。
IntelliJ, Eclipse, STSでSpring Bootを実行する際、以下の場所で環境変数を定義して実行する。
image.png

1.4 Profileを使う

application-prod.propertiesという名前でもう1つプロパティファイルを作成し、Spring Bootを実行する際、以下の場所でVM argumentsに-Dspring.profiles.active=prodを指定して実行する。

image.png

1.5 AutoConfigure

TBD

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