前提
SpringBootにて@ConfigurationProperties
を使ってapplication.yml
の値を読み取る際に以下の警告が出た。
Prefix must be in canonical form {行数}
問題点
読み取り元のyml
ファイルは以下。
application.yml
sampleData:
data1: hoge
data2: fuga
読み取りをするにあたり、下記のように記述していた。
SampleDataConfig.java
@Component
@Setter
@Getter
@ConfigurationProperties(prefix = "sampleData")
public class SampleDataConfig {
String data1;
String data2;
}
解決策
prefix
に指定する値がキャメルケースであることが問題だった。
そのため以下のようにケバブケースでprefix
を指定することで警告が消える。
@ConfigurationProperties(prefix = "sample-data")