As a follow-up on my previous post Solr XML config includes I want to point out another good way to handle environment specific Solr settings: using JNDI. This is not a replacement for XML includes, but in cases where you just need a custom database connection or Solr home dir it might be better suited. Let’s look at two examples.
The most common example is a Solr home dir. Below is an example Tomcat configuration, however JNDI is also available (in some form) in other servlet containers.
<Context docBase="/some/path/solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="/my/solr/home" override="true" /> </Context>
See this solr page for more info on the example above.
Another example: you can also use JNDI for configuring database connections for the DataImportHandler.
Configuration:
<Context docBase="/some/path/solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="/my/solr/home" override="true" /> <Resource name="jdbc/my-database" auth="Container" type="javax.sql.DataSource" username="USERNAME" password="PASSWORD" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://HOST/DATABASE" maxActive="-1"/> </Context>
Usage in data-config.xml:
<dataSource jndiName="java:comp/env/jdbc/my-database" type="JdbcDataSource"/>