Solr 4 plugin configuration - pavelfomin/liferay-clues GitHub Wiki

Instead of hard-coding the url, the solr-spring.xml can be modified to use a property from portal-ext.properties. If the spring configuration must be modified anyway it might as well be enhanced in an environment independent way so the plugin is modified only once and the solr url is controlled via portal-ext.properties in different environments.

Just add the schema definition for context, use context:property-placeholder to read properties from portal-ext.properties and then specify the property for the url:

<?xml version="1.0"?>

<beans
	default-destroy-method="destroy"
	default-init-method="afterPropertiesSet"
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
	<!-- This element activates the replacement of ${...} placeholders, resolved against the specified properties file -->
	<context:property-placeholder location="file:${liferay.home}/portal-ext.properties"/>

	<bean class="com.liferay.portal.spring.context.PortletBeanFactoryPostProcessor" />

	<!-- Solr search engine client -->

	<bean id="com.liferay.portal.search.solr.server.BasicAuthSolrServer" class="com.liferay.portal.search.solr.server.BasicAuthSolrServer">
		<property name="httpRequestInterceptors">
			<list>
				<bean class="com.liferay.portal.search.solr.interceptor.PreemptiveAuthInterceptor" />
			</list>
		</property>
		<property name="url" value="${com.liferay.portal.solr.server.url}" />
	</bean>

If property com.liferay.portal.solr.server.url is not defined in portal-ext.properties, the following error should be expected:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.liferay.portal.search.solr.server.BasicAuthSolrServer' defined in ServletContext resource [/WEB-INF/classes/META-INF/solr-spring.xml]: Could not resolve placeholder 'com.liferay.portal.solr.server.url'
⚠️ **GitHub.com Fallback** ⚠️