solr定時更新索引遇到的問題(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.Null

 問題描述

報以下錯誤,很顯然,問題緣由:空指針異常;java

ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties Error loading DataImportScheduler properties
java.lang.NullPointerException
        at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)
        at sun.nio.fs.UnixPath.<init>(UnixPath.java:71)
        at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281)
        at java.nio.file.Paths.get(Paths.java:84)
        at org.apache.solr.core.SolrResourceLoader.<init>(SolrResourceLoader.java:151)
        at org.apache.solr.handler.dataimport.scheduler.SolrDataImportProperties.loadProperties(SolrDataImportProperties.java:36)
        at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.reloadParams(BaseTimerTask.java:57)
        at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.<init>(BaseTimerTask.java:39)
        at org.apache.solr.handler.dataimport.scheduler.DeltaImportHTTPPostScheduler.<init>(DeltaImportHTTPPostScheduler.java:20)
        at org.apache.solr.handler.dataimport.scheduler.ApplicationListener.contextInitialized(ApplicationListener.java:47)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

詳細緣由:定時更新使用的jar包apache-solr-dataimportscheduler-1.1.jar是網上找的,好像版本更不上了,反編譯一下,問題出在SolrDataImportProperties類的36行,以下標紅位置:apache

    public void loadProperties(boolean force) {
        try {
            SolrResourceLoader loader = new SolrResourceLoader(null);
            logger.info("Instance dir = " + loader.getInstanceDir());

            String configDir = loader.getConfigDir();
            configDir = SolrResourceLoader.normalizeDir(configDir);

個人solr版本是5.5.3,找到org.apache.solr.core.SolrResourceLoader,查看其構造方法,有四個,咱們使用的是public SolrResourceLoader(Path instanceDir),因爲傳入的instanceDir爲null報錯(具體內部代碼就沒調試進去了):測試

  public SolrResourceLoader() {
    this(locateSolrHome(), null, null);
  }

  public SolrResourceLoader(Path instanceDir, ClassLoader parent)
  {
    this(instanceDir, parent, null);
  }

  public SolrResourceLoader(Path instanceDir) {
    this(instanceDir, null, null);
  }

  public SolrResourceLoader(Path instanceDir, ClassLoader parent, Properties coreProperties)
  {
    if (instanceDir == null) {
  ...

如何解決

修改apache-solr-dataimportscheduler-1.1代碼,調用無參構造方法,從新打包,經測試,定時增量更新和全量更新功能正常。this

附件(修改後的jar包)

下載連接:spa

http://files.cnblogs.com/files/chenpi/solr-dataimportscheduler-1.1.1.zip指針

相關文章
相關標籤/搜索