SpringBoot 注解@ConfigurationProperties使用详解

@ConfigurationProperties(prefix = “xx”)

  1. 全局配置文件(application.properties)
    标注在类上,全局配置文件的配置会与被标注的类的属性进行绑定赋值(只要有相应的映射)
  2. 局部配置文件(自定义配置文件)
    @ConfigurationProperties
    @PropertySource(value = {"classpath: "})
    会将自定义配置文件与被标注的类进行绑定
    注意:所有需要被绑定的类需加入容器中方可生效
    即在类上加上@configuration或
    在别的类上使用@configuration加@EnableConfigurationProperties(SecurityProperties.class)

@Configuration
@EnableConfigurationProperties(SecurityProperties.class)
public class SecurityCoreConfig {
}

猜你喜欢

转载自blog.csdn.net/weixin_42074868/article/details/86353127