Pages

Saturday, 17 March 2012

Connecting 2 DBs in Liferay

The following was originally published November 9, 2011 at http://liferayatglance.blogspot.com/2011/11/connecting-to-different-database-using.html


Following are the two simple steps to connect to different databases using Liferay Service Builder:

1) In your service.xml, define the data source name within the entity definition as follows:
<entity name="MultipleDB" local-service="true" table="test_table" remote-service="true" data-source="otherDatasource">

2) Create a new file "ext-spring.xml" under WEB-INF/src/META-INF dir, after building the services. Add following content to the file:

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="otherDatasource" lazy-init="true" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/drxDatasource?useUnicode=true"/>
<property name="username" value="root" />
<property name="password" value="root123" />
</bean>
<bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="otherDatasource" />
</bean>
</beans>

Thats all you need. Create the database and deploy the services.


Thanks to Prashant Yadav, for sharing his knowledge
http://liferayatglance.blogspot.com/2011/01/create-struts-portlet-using-liferay.html#!/2011/11/connecting-to-different-database-using.html

you can also reffer these links :http://liferaylearning.wikispaces.com/http://liferay.wikispaces.com/

2 comments:

  1. informative....thanks.............srikanth....!!!!

    ReplyDelete
  2. Thanks Srikanth for Acknowledging the efforts.

    ReplyDelete