views:

509

answers:

2

I'm developing some portlets for Liferay Portal 5.2.3 with bundled tomcat 6.0.18 using Spring IoC container. I need to map the User_ table used in Liferay database to an entity with Hibernate, so I need to use two different dataSources to separate the liferay db from the db used by portlets.

My jdbc.properties has to hold all connection parameters for both databases: no problem for the one used by portlets, but I am having issues determining which database uses liferay to hold its data.

My conclusion is that i should have something like this:

liferayConnection.url=jdbc:hsqldb:${liferay.home}/data/hsql/lportal

in order to get the database url dynamically loaded, according to Liferay properties found in portal-ext.properties. (Or, better, load the whole portal-ext.properties and read database properties from there).

The problem is that the placeholder is not resolved:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'liferayDataSource' defined in class path resource [WEB-INF/applicationContext.xml]: Could not resolve placeholder 'liferay.home'

To dodge this problem I tried to load explicitly portal-ext.properties with a Spring bean:

<bean id="liferayPropertiesConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="../../portal-ext.properties"/>

but no luck: liferay.home is not resolved but there aren't other errors.

How can I resolve the placeholder defined by Liferay? Thanks

A: 

You can use PropsUtil class (from Liferay) to get values of portal-ext.properties.

String value = PropsUtil.get("key");

Rutvij Shah
thanks Rutvij, I think I'll try to do that. Should be easy in Spring container. In the meanwhile, I hardcoded the jdbc parameters in another .properties file.
mox601
A: 

For loading properties files from an applicationContext.xml file I usually use the PropertiesFactoryBean specifying the location property with a the name of the file located in the classpath, like this:

<bean name="myHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="location">
            <value>classpath:hibernate.properties</value>
        </property>
    </bean>

Make sure the properties files are in a folder/package that is in the classpath.

Bill_BsB