Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 982 Bytes

springboot.md

File metadata and controls

16 lines (12 loc) · 982 Bytes

Clean Code Rules for the Spring Boot

Use @ConfigurationProperties instead of @Value

Rule-ID: springboot.context-no-value-annotation

Spring provides the annotation org.springframework.beans.factory.annotation.Value to inject properties from external property sources into the application context. While this is handsome in plain Spring applications, Spring Boot offers something better: org.springframework.boot.context.properties.ConfigurationProperties. This has the following advantage:

  • No magic strings anymore inside @Value
  • Typed and reusable properties
  • Code completion in application.yaml and application.properties files when using the org.springframework.boot:spring-boot-configuration-processor

See the official Spring documentation for more details