3

我正在使用 Spring IoC 容器为 Liferay Portal 5.2.3 和捆绑的 tomcat 6.0.18 开发一些 portlet。我需要将User_Liferay 数据库中使用的表映射到具有 Hibernate 的实体,因此我需要使用两个不同的数据源将 Liferay db 与 portlet 使用的 db 分开。

jdbc.properties必须保存两个数据库的所有连接参数:portlet 使用的连接参数没有问题,但我在确定哪个数据库使用 liferay 保存其数据时遇到问题。

我的结论是我应该有这样的东西:

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

为了动态加载数据库url,根据portal-ext.properties中的Liferay属性。(或者,更好的是,从那里加载整个portal-ext.properties并读取数据库属性)。

问题是占位符没有解决:

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'

为了避免这个问题,我尝试portal-ext.properties使用 Spring bean 显式加载:

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

但没有运气: liferay.home 没有解决,但没有其他错误。

如何解决 Liferay 定义的占位符?谢谢

4

3 回答 3

1

您可以使用PropsUtil类(来自 Liferay)来获取portal-ext.properties.

String value = PropsUtil.get("key");
于 2010-01-30T02:39:30.010 回答
0

为了从applicationContext.xml文件加载属性文件,我通常使用PropertiesFactoryBean指定location属性和位于类路径中的文件的名称,如下所示:

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

确保属性文件位于类路径中的文件夹/包中。

于 2010-05-11T14:13:04.257 回答
0

您可以PropsUtil使用 SpringEL 调用。例如:

#{T(com.liferay.portal.kernel.util.PropsUtil).get('liferay.home')}

我没有尝试过这个。但是您可以使用以下内容加载所需的 liferay 属性:

<util:properties id="liferayProps">
    <prop key="liferay.home">#{T(com.liferay.portal.kernel.util.PropsUtil).get('liferay.home')}</prop>
</util:properties>
于 2015-11-27T07:57:04.627 回答