繁体   English   中英

Spring Boot初始化花费的时间太长,无法静态初始化具有大量值的Spring Boot属性

[英]Spring boot initialization takes too long to static intialize Spring boot properties with large amount of values

我们在属性文件中有一些静态代码到文本的映射,总代码超过10K,并且我们正在尝试使用静态初始化加载属性文件。 但是初始化应用程序需要2分钟,而无需属性文件,如果我们使用硬编码的hashMap进行初始化,则它非常快。 有没有办法在静态变量中快速加载这些属性?

来自属性文件的几行如下

facetprefix.x4TableMap.cd=CD
facetprefix.x4TableMap.digital=Digital
facetprefix.x4TableMap.lp=LP

@ConfigurationProperties(prefix = "facetprefix")
@PropertySource("classpath:x4-table.properties")
public class X4Table {


    private static Map<String, String> x4TableMap;

    /**
     * initialized map from properties.
     * @param x4TableMap map for x4 table code and values
     */
    public void setX4TableMap(final Map<String, String> x4TableMap) {
        X4Table.x4TableMap = x4TableMap;
    }

    /**
     * @param code Pass in the  x0 code,   get the full x0:  back.
     *             Return "" if the code does not exist in table.
     * @return Pass in the  mt code,   get the full x0: back.
     * Return "" if the code does not exist in table.
     */

    public static String getX4(final String code) {
        return x4TableMap.get(StringUtils.lowerCase(code));



    }
}```

Please let me know if there is a way to Lazy initialize static properties.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM