Wednesday 23 October 2013

Liferay use custom data source instead of liferay default data source via spring-ext.xml updation

Please find the below sample code liferay to use our custom data source. Add/update spring-ext.xml file with below code:



<bean id="testDataSourceTarget" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName">
<value>jdbc/test</value>
</property>
</bean>
<bean id="testDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
<property name="targetDataSource">
<ref bean="testDataSourceTarget" />
</property>
</bean>
<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
<property name="dataSource" ref="testDataSource" />
<property name="sessionFactoryClassLoader" ref="portletClassLoader" />
<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
</bean>
<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="testDataSource" />
</bean>
<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="dataSource">
<ref bean="testDataSource" />
</property>
<property name="sessionFactory">
<ref bean="testHibernateSessionFactory" />
</property>
</bean>