在 Spring Boot 2 中,使用 @EnableConfigurationProperties 注解的作用是让 @ConfigurationProperties 注解生效并绑定相关配置属性。如果你在应用中使用了 @ConfigurationProperties 注解来绑定配置属性,那么通常需要在配置类上使用 @EnableConfigurationProperties 注解来启用该功能。\n\n@EnableConfigurationProperties 注解可以用在 @Configuration 注解修饰的配置类上,表示启用 @ConfigurationProperties 注解绑定配置属性。\n\n例如:\n\n@Configuration\n@EnableConfigurationProperties(MyProperties.class)\npublic class MyConfig {\n // ...\n}\n\n这段代码中,@EnableConfigurationProperties(MyProperties.class) 启用了 @ConfigurationProperties 注解,用于绑定 MyProperties 类中的配置属性。\n\n总结来说,如果你在应用中使用了 @ConfigurationProperties 注解来绑定配置属性,那么就需要在配置类上使用 @EnableConfigurationProperties 注解来启用该功能。否则,不需要加上 @EnableConfigurationProperties 注解。


原文地址: http://www.cveoy.top/t/topic/pNqU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录