障害メモ/ConfigurationPropertiesでプロパティ設定を読めない
キーワード
- Spring Boot
- ConfigurationProperties
- application.properties
- application.yml
現象
プロパティ設定を読めるという@ConfigurationPropertiesでプロパティ設定をセットできていない。
@Value
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix="application.web")
public class WebProperties {
private String contextpath;
}
原因
setterがない。
対策
@Valueでなくて@Dataでないといけない。
@Data
@Component
@ConfigurationProperties(prefix="application.web")
public class WebProperties {
private String contextpath;
}
備考
Springは素直にsetterを探しに行ってるんですね。
参考
作成日 2017-03-31
