zoukankan      html  css  js  c++  java
  • @ConfigurationProperties注解作用

    今天遇到一个疑惑点,在配置文件中用了一组类似的配置,如下:

    data.hashmap.1=d1
    data.hashmap.2=d2
    data.hashmap.3=d3
    data.hashmap.4=d4
    data.hashmap.5=d5
    data.hashmap.6=d6
    View Code

    然后在springboot中添加了配置config文件,代码如下

    @Data
    @Component
    @ConfigurationProperties(prefix = "data")
    public class xxxConfig {
        private Map<String, String> hashmap;
    }

    这时只要在需要的地方Autowired这个配置类,里面的hashmap中就已经附上值了。

    这里我就非常奇怪了,赋值一般不都是通过@Value或者是其他的具体方法实现的么,而我在这里什么也没找到。

    最后看了半天,还是把目光盯在了@ConfigurationProperties上,百度一搜才知道我把这个注解想简单了

    本以为这个注解就是定义一下配置文件中要找的对象的前缀

    但实际上功能不止这些,这个注解还会自动封装注解的类,所以这里就对xxxConfig自动封装,将值赋给hashmap了

  • 相关阅读:
    python-通过psutil监控系统性能
    集合类和JAVA多线程
    JAVA异常和基础类库
    类设计基础与进阶
    面对对象思想
    AtCoder Beginner Contest 185
    Java概述
    友链
    牛客编程巅峰赛S2第7场
    牛客小白月赛30
  • 原文地址:https://www.cnblogs.com/tianphone/p/11052558.html
Copyright © 2011-2022 走看看