Read the list in nacos configuration

1. Scenario
There are some constant but commonly used data, which can be directly written in nacos for easy reading and management.
Here is a list collection read from nacos, the content of the collection is an object

sopconditions:  
  sopcondition:
    - sopConditionEnum: 1
      approvalType: 0  
      conditionName: "营销方类型是否是电厂"
      bussinessBodys: [0, 1, 5, 6]
      inkeys:
        - alias: "id"
          name: "id"
          type: "String"
          necessary: true
          defaultValue: ""
        - alias: "sopConditionEnum"
          name: "sopConditionEnum"
          type: "String"
          necessary: true
          defaultValue: "1"          
      outkeys:
        - alias: "result"
          name: "result"
          type: "String"
          address: "String"
          defaultValue: "是;否"
          values: null
          autoValues: null
    - sopConditionEnum: 2
      approvalType: 0
      conditionName: "合同类别"
      bussinessBodys: [0, 1, 5, 6]
      inkeys:
        - alias: "id"
          name: "id"
          type: "String"
          necessary: true
          defaultValue: ""
        - alias: "sopConditionEnum"
          name: "sopConditionEnum"
          type: "String"
          necessary: true
          defaultValue: "2"
      outkeys:
        - alias: "contractType"
          name: "合同类别"
          type: "String"
          address: "String"
          defaultValue: "电力贸易;综合能源;电力贸易和综合能源"
          values: null
          autoValues: null

2. Specific operations
2.1 Add the location of the configuration yaml read by nacos in the yaml file configuration
2.2 Define the corresponding entity class
2.3 Use the @ConfigurationProperties annotation to automatically read
@ConfigurationProperties Function: map each attribute value configured in the configuration file to in this component. Tell springboot to bind all the attributes in this class and the relevant configuration in the configuration file
@Configuration: it means it is a configuration file, so that spring can scan to the
List it defines. The sopcondition attribute is used to receive the list read in nacos assembled


```java
@Configuration
@ConfigurationProperties(prefix = "sopconditions")
@Data
public class SopConditionProperties {
    
    

//    @Value("${
    
    sopcondition:[]}")
    private List<SopCondition> sopcondition;



    public List<SopCondition> getList(){
    
    
        return sopcondition;
    }

    public void setList(List<SopCondition> sopConditions){
    
    
        this.sopcondition = sopConditions;
    }

}


Guess you like

Origin blog.csdn.net/weixin_45933454/article/details/126054628