0
0

More than 1 year has passed since last update.

【Spring Boot】@ConfigurationPropertiesの『Prefix must be in canonical form』を解決する

Last updated at Posted at 2023-01-25

前提

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")
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