zoukankan      html  css  js  c++  java
  • @ConfigurationProperties

      为了更灵活额配置,我们将参数配置在application.properties或者yml中@ConfigurationProperties注解获取到参数值

      在application.yml中写下

    route:
      name:
        a: /1
        b: /2
        c: /3
        d: /4
      url:
        a: 127.0.0.1:8080
        b: 127.0.0.1:8081
        c: 127.0.0.1:8082
        d: 127.0.0.1:8083

      配置类

      当项目启动时会自动把配置文件信息读取到map中

    @Data
    @Component
    @ConfigurationProperties(prefix = "route")
    public class Test {
        private Map<String, String> name;
        private Map<String, String> url;
    }

      使用

    @Autowired Test test;
    
    public String getUrl(String text){
        Map<String, String> name = new HashMap<>();
        Map<String, String> url = new HashMap<>();
        name = test.getName();
        url = test.getUrl();
        return url.get(text) + name.get(text);
    }

      可以把路由信息写在配置文件中这样可以只改动配置文件,不改动代码。

  • 相关阅读:
    jmeter结果分析
    JMeter分布式测试
    负载测试
    10.循环控制语句break_continue_pass
    9.控制流语句_for循环
    7.Python 循环语句
    8.控制流语句_while循环
    6.控制流语句_条件控制if
    5.运算符
    4.元祖_列表_字典
  • 原文地址:https://www.cnblogs.com/liljoker/p/13778878.html
Copyright © 2011-2022 走看看