LoginSignup
1
0

More than 5 years have passed since last update.

@ConfigurationProperties の prefix でちょっとはまった

Posted at

例えば、下記のような設定だったとして、

application-37.yml
file: 
  37: 
    file-name: hoge
application.yml
spring: 
  profiles: 
    active: 37
File37Context.java
@ConfigurationProperties(prefix = "file.37")
pulic class File37Context {
  String fileName;
  // setter,getter
}

spring-boot 2.0.6 では fileName が取得できたのに、
spring-boot 1.5.17 では null になってしまった。

どうやら 37 の部分が配列の数字?と認識されたような動きで、

File37Context.java
@ConfigurationProperties(prefix = "file[37]")
pulic class File37Context {
  String fileName;
  // setter,getter
}

と修正すると spring-boot 1.5.17 でも値が取得できるようになった。
数字だけってのがダメっぽい。

気持ち悪いので、

application-37.yml
file: 
  type37: 
    file-name: hoge
File37Context.java
@ConfigurationProperties(prefix = "file.type37")
pulic class File37Context {
  String fileName;
  // setter,getter
}

って感じで数字以外を付与してあげることで、最終的に解決。

問題がjavaなのかspringなのかtomcatなのかで最初は全然わからなくてちょっと時間かかった。。。

仕事で使わなきゃいけない動作環境がjdk1.6ってことでなんだかわけわかんなくなるような作り方してるけど、なんだかなぁ。。。
こんなので嵌る人って他にいるのかなぁ。。。

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