Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using properties from solrcore.properties in data-config.xml (Solr 4.2.1)

We are trying to upgrade from Solr 3.6.2 to Solr 4.2.1 and are having problems with using properties in solrcore.properties in data-config.xml.

With Solr 3.6.2, we were able to directly use properties in solrcore.properties inside data-config.xml like:

<dataSource driver="${jdbc.driver}" 
            url="jdbc:mysql://${jdbc.host}:${jdbc.port}/${db.name}" 
            user="${jdbc.username}" 
            password="${jdbc.password}" 
            batchSize="-1" />

Now these properties are not found, so when I invoke dataimport it throws this exception:

Apr 26, 2013 11:10:58 AM org.apache.solr.common.SolrException log
SEVERE: Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver:  Processing Document # 1
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:266)
    at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:422)
    at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:487)
    at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:468)
Caused by: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver:  Processing Document # 1
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:406)
    at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:319)
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:227)
    ... 3 more
Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver:  Processing Document # 1
    at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:71)
    at org.apache.solr.handler.dataimport.JdbcDataSource.createConnectionFactory(JdbcDataSource.java:114)
    at org.apache.solr.handler.dataimport.JdbcDataSource.init(JdbcDataSource.java:62)
    at org.apache.solr.handler.dataimport.DataImporter.getDataSourceInstance(DataImporter.java:394)
    at org.apache.solr.handler.dataimport.ContextImpl.getDataSource(ContextImpl.java:99)
    at org.apache.solr.handler.dataimport.SqlEntityProcessor.init(SqlEntityProcessor.java:53)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.init(EntityProcessorWrapper.java:74)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:423)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:404)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: Unable to load  or org.apache.solr.handler.dataimport.
    at org.apache.solr.handler.dataimport.DocBuilder.loadClass(DocBuilder.java:911)
    at org.apache.solr.handler.dataimport.JdbcDataSource.createConnectionFactory(JdbcDataSource.java:112)
    ... 12 more
Caused by: org.apache.solr.common.SolrException: Error loading class ''
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:440)
    at org.apache.solr.handler.dataimport.DocBuilder.loadClass(DocBuilder.java:901)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: 
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:424)
    ... 14 more

If I hard code the properties in data-config.xml, then the import works fine.

Both data-config.xml and solrcore.properties are under the dir project_name/solr/app-cores/core_name/conf

Then took hint from here and tried configuring the properties in the data import request handler in solr-config.xml like this:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
        <str name="config">data-config.xml</str>
        <str name="jdbcDriver">${jdbc.driver}</str>
        <str name="jdbcHost">${jdbc.host}</str>
        <str name="jdbcPort">${jdbc.port}</str>
        <str name="jdbcUsername">${jdbc.username}</str>
        <str name="jdbcPassword">${jdbc.password}</str>
    </lst>
</requestHandler>

and use them in data-config.xml like {dataimport.jdbcDriver} and {dataimport.request.jdbcDriver} but those are throwing the same exception!

How to fix this?

like image 295
arun Avatar asked Apr 26 '13 18:04

arun


1 Answers

Using ${dataimporter.request.jdbcDriver} with the request handler approach worked!

like image 119
kenorb Avatar answered Nov 15 '22 09:11

kenorb