Blogs

Blogs

connect to external database via Service-Builder

for Liferay CE 7.4.2 GA3

I struggle on this for over 3 weeks. god...

my envirement

Liferay CE 7.4.2 GA3

Oracle JDK 8

Windows 10

Liferay Developer Studio Version: 3.9.4.202108090632-ga5

 

sometime, we have to connect to another database for many reasons, system is old, they cannot provide web service..etc.

 

there have two ways for this purpose, DataSourceProvider and SpringBeans

IMPORTANT!

1. before start, we have to download ojdbc.jar, because i use jdk8 and my target database is Oracle, so i need ojdbc8.jar, and put it on TOMCAT_HOME\webapps\ROOT\WEB-INF\shielded-container-lib

2. download  liferay-portal-database-all-in-one-support and put it in TOMCAT_HOME\webapps\ROOT\WEB-INF\lib

3. in your -service module's bnd.bnd after "-dsannotations-options: inherit" add follows:

Import-Package: \
    org.springframework.jdbc.datasource,\
    com.liferay.portal.dao.jdbc.spring,\
    *
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
Liferay-Spring-Context: META-INF/spring

 

Especially the point 3, there is no document mentioned so far (maybe I have not studied deeply enough)

Super thank to Mr. Antonio Musarra. He selflessly shared code and suggestions, which helped me a lot.