栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

@ConfigurationProperties注解解析

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

@ConfigurationProperties注解解析

关于EnableConfigurationProperties,在SpringBoot的注释中是这样说明的:为带有@ConfigurationProperties注解的Bean提供有效的支持。

@EnableConfigurationProperties的作用是把springboot配置文件中的值与我们的RegistrationTypeProperties .java的属性进行绑定,需要配合@ConfigurationProperties使用 (需要加@Component)

ConfigurationProperties
@Component
@ConfigurationProperties(prefix = "config")
@RefreshScope
@Data
public class RegistrationTypeProperties {

    private Integer xyType;

    private Integer pushType;

}

@ConfigurationProperties 注解,通常是将properties和yml文件转换成bean对象;

以上步骤可以将配置文件属性注册到IOC容器中,在获取这些bean之前,首先需要使用@EnableConfigurationProperties({ConfigBean.class})  注解使ConfigurationProperties注解生效:

@MapperScan("com.capinfo.*.mapper")
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableConfigurationProperties({
        RegistrationTypeProperties.class
})
public class PerceptionApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(PerceptionApplication.class, args);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/979213.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号