0
0

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 1 year has passed since last update.

【Spring Boot】プロパティファイルをまるごと取得する方法

Last updated at Posted at 2023-06-21

Spring Bootでプロパティファイルを参照する場合は@Valueを使うことが多いかと思います。ですが、参照したい値が多くひとつひとつ書くのが面倒だったので、下記の方法を使用しました。

プロパティファイルの準備

プロパティファイルはresorces直下に置きます。

hoge.properties
a=apple
b=banana
c=cherry
d=durian

プロパティファイルを参照

Properties properties = new Properties();
try {
    InputStream istream = new ClassPathResource('hoge.properties').getInputStream();
    properties.load(istream);
} catch (Exception ignore) {}

var name = properties.getProperty("a");

参考になれば幸いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?