Liferay service builder connects with other database
来源:互联网 发布:乔安官网软件下载 编辑:程序博客网 时间:2024/05/01 17:53
1. We need to do some change in our service.xml. Here, we need to specify our own data-source, session-factory, tx-manager. If we don't specify them, it won't work. Previously, I didn't do that, it always connects with Liferay database.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.rujuan.book">
<author>Tina Xing</author>
<namespace>BookStore</namespace>
<entity name="Book" local-service="true" remote-service="false"
uuid="true" data-source="myAppDataSource" session-factory="myAppSessionFactory" tx-manager="myAppTransactionManager">
<column name="bookid" type="long" primary="true" />
<column name="title" type="String" />
<column name="authorname" type="String" />
<column name="isbn" type="String" />
<column name="summary" type="String" />
<column name="status" type="int"></column>
<column name="statusByUserId" type="long"></column>
<column name="statusByUserName" type="String"></column>
<column name="statusDate" type="Date"></column>
<column name="companyId" type="long"></column>
<column name="groupId" type="long"></column>
<column name="userId" type="long"></column>
<!-- <reference package-path="com.liferay.portal" entity="User" />
<reference package-path="com.liferay.asset" entity="AssetEntry" />
<reference package-path="com.liferay.ratings" entity="RatingsStats" />
<reference package-path="com.liferay.portal" entity="Resource" />
<reference package-path="com.liferay.portal" entity="WorkflowInstanceLink" /> -->
</entity>
</service-builder>
2. write our own ext-spring.xml. In the file, we configure the second datasource, session factory etc. We put the file in /WEB-INF/src/META-INF which is the folder contains a lot of other spring,hibernate xml.
<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>
<bean id="myAppDataSourceTarget"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="myAppDataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref bean="myAppDataSourceTarget" />
</property>
</bean>
<bean id="myAppHibernateSessionFactory"
class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource">
<ref bean="myAppDataSource" />
</property>
</bean>
<bean id="myAppSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl">
<property name="sessionFactoryImplementor">
<ref bean="myAppHibernateSessionFactory" />
</property>
</bean>
<bean id="myAppTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource">
<ref bean="myAppDataSource" />
</property>
<property name="sessionFactory">
<ref bean="myAppHibernateSessionFactory" />
</property>
</bean>
</beans>
3. Write jdbc.properties, put in WEB-INF folder
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/liferay
jdbc.username=root
jdbc.password=root
4. make sure ext-spring.xml is configured in your service.properties, like this
spring.configs=\
WEB-INF/classes/META-INF/base-spring.xml,\
\
WEB-INF/classes/META-INF/hibernate-spring.xml,\
WEB-INF/classes/META-INF/infrastructure-spring.xml,\
\
WEB-INF/classes/META-INF/cluster-spring.xml,\
\
WEB-INF/classes/META-INF/portlet-spring.xml,\
\
WEB-INF/classes/META-INF/dynamic-data-source-spring.xml,\
WEB-INF/classes/META-INF/shard-data-source-spring.xml,\
\
WEB-INF/classes/META-INF/ext-spring.xml
All configurations are done. It's very easy right. But it took me a lot of time to configure. The reason is because of the first step. Good luck!
- Liferay service builder connects with other database
- Install liferay framework and integrate with MySql or other database
- Liferay 6.1开发Service Builder
- Transaction Management with Liferay Service
- Liferay:Service Builder的DTD内容
- PHP connects Hostinger MySQL database
- Liferay 6.1开发学习(四):Service Builder
- Liferay DXP Soy portlet系列(三 )使用Service Builder创建 JSON Web Service
- Other Database Checks
- liferay项目部署报错 Service Builder BeanLocator has not been set
- liferay service builder Could not reserve enough space for object heap
- 使用Liferay IDE 3.0创建支持Service Builder的portlet module
- Liferay开发实战(2):Service Builder生成持久化层,及开发服务层
- Liferay Service Build(II)
- Liferay Service Build
- Liferay连接第二个database
- Ignoring query to other database
- Ignoring query to other database
- Linux/ubuntu下编辑/etc/fstab实现开机自动挂载分区方法
- CentOS系统安装过程中配置软RAID-0或RAID-1
- matlab 怎样画颜色渐变曲线
- DIV+CSS布局:DIV层重叠
- QT4.7.3移植GT2440
- Liferay service builder connects with other database
- 如何在Edit实现右键菜单
- solr 搜索架构优化
- 延时启动脚本
- NEST LOOP JOIN 和MERGE JOIN
- 详解Android源码的编译
- div的position的四种定位
- _stdcall详解
- AsyncTask 也会引起线程不安全(抛出异常:CalledFromWrongThreadException)?