首页 > 其他分享 >ApiContainer

ApiContainer

时间:2022-11-10 20:57:16浏览次数:49  
标签:java apiTemplate springframework util ApiContainer import public

 1 package com.-.it.regioc.container;
 2  
 3 import cn.hutool.core.collection.CollectionUtil;
 4 import com.huawei.it.regioc.bean.apiconfig.ApiTemplate;
 5 import lombok.Data;
 6 import org.springframework.beans.factory.InitializingBean;
 7 import org.springframework.boot.context.properties.ConfigurationProperties;
 8 import org.springframework.context.annotation.Configuration;
 9 import java.io.FileNotFoundException;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13  
14  
15 @Data
16 @Configuration
17 @ConfigurationProperties(prefix = "api", ignoreInvalidFields = true)
18 public class ApiContainer implements InitializingBean {
19  
20     private List<ApiTemplate> apiList;
21  
22  
23     public static Map<String, ApiTemplate> apiMap = new HashMap<>();
24  
25     @Override
26     public void afterPropertiesSet() throws FileNotFoundException {
27         if (CollectionUtil.isEmpty(apiList)) {
28             throw new FileNotFoundException("api列表为空");
29         }
30         for (ApiTemplate apiTemplate : apiList) {
31             apiMap.put(apiTemplate.getId(), apiTemplate);
32         }
33     }
34  
35     /**
36      * 该方法可能会返回null,请注意判断
37      */
38     public static ApiTemplate getApiById(String id) {
39         return apiMap.get(id);
40     }
41  
42 }
43  

 

标签:java,apiTemplate,springframework,util,ApiContainer,import,public
From: https://www.cnblogs.com/mingruifeng/p/16878739.html

相关文章