spring - 从 Spring IoC 容器加载 Liferay 属性(获取 jdbc 连接参数)

标签 spring properties liferay

我正在使用 Spring IoC 容器为 Liferay Portal 5.2.3 和捆绑的 tomcat 6.0.18 开发一些 portlet。
我需要映射 User_ Liferay 数据库中使用的 table 到具有 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 定义的占位符?谢谢

最佳答案

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

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

关于spring - 从 Spring IoC 容器加载 Liferay 属性(获取 jdbc 连接参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2153535/

相关文章:

java - 读取多模块项目中的属性文件

eclipse - Eclipse 中的 Liferay 开发

Liferay - 同一 portlet 的已部署版本和未部署版本之间的差异

spring - 向多个 RabbitMQ 消费者提供相同的消息

spring - 我可以在Grails应用程序中的何处存储(保留)Java应用程序的xml文件

java - 删除 commons-logging 并使用 slf4j 会导致 spring 出现错误

c# - 有没有理由拥有没有 setter/getter 的属性(property)?

PHPUnit 在测试类上存储属性

integration - 在 Liferay 和 Alfresco 之间集成 WCM

java - 多个 JpaRepositories 方法的一个事务