What difference does @EnableConfigurationproperties make if a bean is already annotated with @ConfigurationProperties?

前端 未结 3 781
一个人的身影
一个人的身影 2021-01-31 08:20

The Spring Boot documentation says that to use the @ConfigurationProperties annotation

You also need to list the properties classes to regis

3条回答
  •  醉梦人生
    2021-01-31 08:45

    If we look at the code below:

    @Configuration @EnableConfigurationProperties @ConfigurationProperties(prefix="ar1") public class ar1Settings { }

    • @Configuration tells Spring to treat this as a configuration class and register it as a Bean

    • @EnableConfigurationProperties tells Spring to treat this class as a consumer of application.yml/properties values

    • @ConfigurationProperties tells Spring what section this class represents.

    My understanding is that if you don't need to specify the section of the property file, then @ConfigurationProperties can be omitted.

提交回复
热议问题