因为IK实在第一次分词时才加载词典,可能会导致第一次分词较慢,所以打算在Tomcat启动时就加载到内容,提高速度。步骤如下:
1. 实现ServletContextListner接口
在contextInitialized(ServletContextEvent arg0)方法中,初始化加载:
2. 在程序的web.xml中加入此listner的调用:
这样,tomcat启动日志中就能看到正确加载。
1. 实现ServletContextListner接口
在contextInitialized(ServletContextEvent arg0)方法中,初始化加载:
System.out.println("tomcat启动:初始化词典");
org.wltea.analyzer.dic.Dictionary.initial(org.wltea.analyzer.cfg.Configuration.getInstance());
2. 在程序的web.xml中加入此listner的调用:
<listener>
<listener-class>com.blackwing.util.LoadDicListner</listener-class>
</listener>
这样,tomcat启动日志中就能看到正确加载。