Liferay will support our API and resolve any issues and answer any questions having to do with the API itself or any other part of Liferay's software. Issues and questions regarding custom development may be handled by our Global Services team or by the developer of those customizations.
This article documents how to access data stored on non-Liferay databases (e.g. different database schema or server) in Liferay DXP and beyond.
Resolution
- Specify the appropriate external datasource, etc., as necessary in the
service.xml
- For example, specify
extDataSource
- For example, specify
- Follow the steps for creating a service builder module according to this documentation: Service Builder and Services (e.g., generating services, etc.)
- Add your custom datasource definition in a spring configuration file and call it
liferayDataSource
- Add an alias definition from
liferayDataSource
toextDataSource
- For example
<alias name="liferayDataSource" alias="extDataSource" />
- For example
This will allow you to leverage the base functionality provided by the liferay-portal-spring-extender
, assuming you defined in your Bnd directives to activate Liferay-Spring-Context
and Liferay-Service
.
Constraints to Consider:
- Only one data source per module may be used. Therefore, each external data source will need to be encapsulated in its own service builder module.
- Cannot mix usage of the Liferay database with an external data source within the same module.
Additional Information
Caution
- Anytime multiple data sources are used with intent to WRITE to multiple data sources within the same transaction, you MUST use an XA transaction manager and XA datasources (otherwise known as 2-phase commit). If you do not, transactional integrity will be lost. This same principal applied even prior to DXP 7.0.
- If you need additional flexibility (e.g. create multiple-data-sources) you can ask the spring extender to not activate the default service support but still use Spring for transactional control, etc. Specify
Liferay-Service: false
andLiferay-Spring-Context: true
. - This will basically tell the spring extender to not load the base spring configs (e.g.
portal-spring-extender/src/main/resources/META-INF/spring/parent
). The configurations in this directory setup base Liferay Service requirements (e.g. aspects, etc). You can always set up your own, including any datasources and transaction managers used within the service builder generated code. You must use theLiferay-Spring-Context
directive because transaction management aspects are not supported in OSGi's Declarative Services at this stage.
Conteúdo Excluesivo para Assinantes
Uma Subscrição do Liferay Enterprise fornece acesso a mais de 1.500 artigos que incluem práticas recomendadas, solução de problemas e outras soluções valiosas. Faça login para obter acesso completo.
Entrar