@ConfigurationProperties versus @Value

In our code, we have used both strongly-type @ConfigurationProperties based classes as well as @Value labeled attributes. It's important to understand the differences before using them in your application.

@Value is old, preceding Spring Boot by years. It is a powerful annotation, able to inject values as well as accept default values. However, it misses several features many of us have come to rely upon when writing Boot apps, as shown in the following table:

Feature

@ConfigurationProperties

@Value

Relaxed binding

Yes

No

Meta-data support

Yes

No

SpEL evaluation

No

Yes

This matrix documents three critical features:

  • Relaxed binding: The ability to match server.port ...

Get Learning Spring Boot 2.0 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.