ansj_seg-5.0.3 MyStatic部分源码阅读

static {
        /**
         * 配置文件变量
         */
        ResourceBundle rb = null;
        try {
            rb = ResourceBundle.getBundle("ansj_library");
        } catch (Exception e) {
            try {
                File find = FileFinder.find("ansj_library.properties", 1);
                if (find != null && find.isFile()) {
                    rb = new PropertyResourceBundle(
                            IOUtil.getReader(find.getAbsolutePath(), System.getProperty("file.encoding")));
                    LIBRARYLOG.info(
                            "load ansj_library not find in classPath ! i find it in {} make sure it is your config!",
                            find.getAbsolutePath());
                }
            } catch (Exception e1) {
                LIBRARYLOG.warn("not find ansj_library.properties. and err {} i think it is a bug!", e1.getMessage());
            }
        }

        if (rb == null) {
            try {
                rb = ResourceBundle.getBundle("library");
            } catch (Exception e) {
                try {
                    File find = FileFinder.find("library.properties", 2);
                    if (find != null && find.isFile()) {
                        rb = new PropertyResourceBundle(
                                IOUtil.getReader(find.getAbsolutePath(), System.getProperty("file.encoding")));
                        LIBRARYLOG.info(
                                "load library not find in classPath ! i find it in {} make sure it is your config!",
                                find.getAbsolutePath());
                    }
                } catch (Exception e1) {
                    LIBRARYLOG.warn("not find library.properties. and err {} i think it is a bug!", e1.getMessage());
                }
            }
        }

        DIC.put(DIC_DEFAULT, "library/default.dic");

        if (rb == null) {
            LIBRARYLOG.warn("not find library.properties in classpath use it by default !");
        } else {

            for (String key : rb.keySet()) {

                if (key.equals("dic")) {
                    DIC.put(key, rb.getString(key));
                } else if (key.equals("crf")) {
                    CRF.put(key, rb.getString(key));
                } else if (key.startsWith("dic_")) {
                    if (DIC.containsKey(key)) {
                        LIBRARYLOG.warn("{} dic config repeat definition now overwrite it !", key);
                    }
                    DIC.put(key, rb.getString(key));
                } else if (key.startsWith("crf_")) {
                    if (CRF.containsKey(key)) {
                        LIBRARYLOG.warn("{} crf config repeat definition now overwrite it !", key);
                    }
                    CRF.put(key, rb.getString(key));
                } else {
                    try {
                        Field field = MyStaticValue.class.getField(key);
                        field.set(null, ObjConver.conversion(rb.getString(key), field.getType()));
                    } catch (NoSuchFieldException e) {
                        LIBRARYLOG.error("not find field by {}", key);
                    } catch (SecurityException e) {
                        LIBRARYLOG.error("安全异常", e);
                    } catch (IllegalArgumentException e) {
                        LIBRARYLOG.error("非法参数", e);
                    } catch (IllegalAccessException e) {
                        LIBRARYLOG.error("非法访问", e);
                    }
                }

            }

        }
    }
  • 此静态块用于加载ansj配置文件。

  • 我不明白的是,为什么在WEB-INF下面建立classes目录,其中放properties配置文件,solr日志却报错说“classpath”目录下没有配置文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值