论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Lambert Mickael
Service Builder - External Database
2012年11月14日 上午9:13
答复

Lambert Mickael

等级: Junior Member

帖子: 58

加入日期: 2011年12月29日

最近的帖子

Hello everyone

I tried to connect an external database to my service builder. For that i follow all of those steps :

1) In my service.xml i add this :
1<entity name="EventTracker" local-service="true" remote-service="false" data-source="myDatasource">


2) I created my file : "ext-spring.xml" :

 1<?xml version="1.0"?>
 2<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">
 3
 4    <bean id="myDatasource" lazy-init="true"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 5        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
 6        <property name="url" value="jdbc:mysql://192.168.*.***/mydatabase?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"/>
 7        <property name="username" value="myusername" />
 8        <property name="password" value="mypassword" />
 9    </bean>
10</beans>


3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)

But when i try to add a row in my table, an error tells me that i try to connect at lportal database...

Can anyone help me please ?
David H Nebinger
RE: Service Builder - External Database
2012年11月14日 上午9:53
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 11100

加入日期: 2006年9月1日

最近的帖子

Is your ext-spring.xml in the META-INF folder of the service providing project?
Lambert Mickael
RE: Service Builder - External Database
2012年11月15日 上午12:39
答复

Lambert Mickael

等级: Junior Member

帖子: 58

加入日期: 2011年12月29日

最近的帖子

David H Nebinger:
Is your ext-spring.xml in the META-INF folder of the service providing project?


Yes it is! With the others files :

- base-spring.xml
- cluster-spring.xml
- dynamic-data-source-spring.xml
- hibernate-spring.xml
... etc.
Lambert Mickael
RE: Service Builder - External Database
2012年11月15日 上午2:49
答复

Lambert Mickael

等级: Junior Member

帖子: 58

加入日期: 2011年12月29日

最近的帖子

Here is my service.xml file if it can helps anyone.

I really need help! Please ...

 1?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
 3<service-builder package-path="com.events.database">
 4    <author>mlambert</author>
 5    <namespace>E</namespace>
 6
 7    <entity name="EventTracker" local-service="true" remote-service="false" data-source="myDatasource">
 8
 9        <!-- PK fields -->
10
11        <column name="id" type="long" primary="true" />
12
13        <!-- Audit fields -->
14
15        <column name="company_id" type="long" />
16        <column name="user_id" type="long" />
17        <column name="group_id" type="long" />
18        <column name="organisation_id" type="long" />
19        <column name="date" type="Date" />
20        <column name="service" type="String" />
21        <column name="description" type="String" />
22        <column name="type_event" type="String" />
23        <column name="info_statut" type="String" />
24       
25        <order by="asc">
26          <order-column name="id"></order-column>
27           </order>
28          
29          <finder return-type="Collection" name="GroupId">
30               <finder-column name="group_id"></finder-column>
31           </finder>
32          <finder return-type="Collection" name="CompanyId">
33              <finder-column name="company_id"></finder-column>
34          </finder>
35          <finder return-type="Collection" name="UserId">
36              <finder-column name="user_id"></finder-column>
37          </finder>
38          <finder return-type="Collection" name="OrganisationId">
39              <finder-column name="organisation_id"></finder-column>
40           </finder>
41           <finder return-type="Collection" name="Service">
42              <finder-column name="service"></finder-column>
43           </finder>
44          <finder return-type="Collection" name="TypeEvent">
45              <finder-column name="type_event"></finder-column>
46           </finder>
47           <finder return-type="Collection" name="UserService">
48              <finder-column name="user_id"></finder-column>
49               <finder-column name="service"></finder-column>
50           </finder>
51           <finder return-type="Collection" name="InfoStatut">
52              <finder-column name="info_statut"></finder-column>
53           </finder>
54    </entity>
55</service-builder>
David H Nebinger
RE: Service Builder - External Database
2012年11月15日 上午5:35
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 11100

加入日期: 2006年9月1日

最近的帖子

Lambert Mickael:
3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)


You should not be moving the jar. The service jar must be available for both portlets.

In the IDE you add the context for the plugin providing the service as a required deployment context. The IDE will copy (not move) the service jar to the other portlet.
Lambert Mickael
RE: Service Builder - External Database
2012年11月15日 上午5:51
答复

Lambert Mickael

等级: Junior Member

帖子: 58

加入日期: 2011年12月29日

最近的帖子

David H Nebinger:
Lambert Mickael:
3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)


You should not be moving the jar. The service jar must be available for both portlets.

In the IDE you add the context for the plugin providing the service as a required deployment context. The IDE will copy (not move) the service jar to the other portlet.


The other project is a hook, i did it, but it didn't solve my problem :s
David H Nebinger
RE: Service Builder - External Database
2012年11月19日 上午5:53
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 11100

加入日期: 2006年9月1日

最近的帖子

Hooks have entirely different issues than portlets...

Hooks typically run within the ROOT context but will not have the service jar available. To make the service jar available to the ROOT context, you should follow the old method of moving the service jar from the portlet providing the service to the global lib directory (lib/ext in tomcat).
Laura Liparulo
RE: Service Builder - External Database
2012年12月30日 上午4:11
答复

Laura Liparulo

等级: Junior Member

帖子: 38

加入日期: 2012年6月30日

最近的帖子

You need to launch the ant build-service command, the add the ext-spring.xml in the /docroot/WEB-INF/src/META-INF folder. Then you can deploy your portlet.
Example:

service.xml
------------------
 1
 2<?xml version="1.0" encoding="UTF-8" ?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
 4
 5<service-builder package-path="it.dicom">
 6    <author>Laura Liparulo</author>
 7    <namespace>dicomViewer</namespace>
 8
 9
10<entity name="Volume" local-service="true" remote-service="true" table="volume"
11 data-source="dicomViewerDataSource" session-factory="dicomViewerSessionFactory" tx-manager="dicomViewerTransactionManager">
12        <!-- PK Fields -->
13        <column name="volumeId" type="long" primary="true" />
14        <!-- Other Fields -->
15        <column name="volumeName" type="String" />
16        <column name="overview" type="String" />
17        <column name="folderLink" type="String" />
18        <!-- Relationships -->
19        <column name="caseVolume" type="Collection" entity="CaseArchive"
20            mapping-key="volumeId" />
21        <order by="asc">
22            <order-column name="volumeName" />
23        </order>
24        <finder name="Volume_Name" return-type="Collection">
25            <finder-column name="volumeName" />
26        </finder>
27    </entity>
28
29
30
31    <entity name="CaseArchive" local-service="true" remote-service="true" table="case_archive"
32 data-source="dicomViewerDataSource" session-factory="dicomViewerSessionFactory" tx-manager="dicomViewerTransactionManager">
33        <!-- PK Fields -->
34        <column name="caseId" type="long" primary="true" />
35        <!-- Other Fields -->
36        <column name="caseName" type="String" />
37        <column name="volumeId" type="long" />
38        <column name="notes" type="String" />
39        <!-- Relationships -->
40        <column name="image_Case" type="Collection" entity="Image"
41            mapping-key="caseId" />
42        <order by="asc">
43            <order-column name="caseName" />
44        </order>
45        <finder name="Case_Name" return-type="Collection">
46            <finder-column name="caseName" />
47        </finder>
48    </entity>
49
50
51   
52
53
54</service-builder>


ext-spring.xml
------------------

 1
 2<?xml version="1.0"?>
 3<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 4"http://www.springframework.org/dtd/spring-beans.dtd">
 5<beans>
 6  <bean class="
 7org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 8  </bean>
 9  <bean id="dicomViewerDataSourceTarget"               
10     class="org.springframework.jdbc.datasource.DriverManagerDataSource">
11    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
12    <property name="url" value="jdbc:mysql://localhost:3306/Unicas-Dicom-Viewer" />
13    <property name="username" value="root" />
14    <property name="password" value="tigertailz" />
15  </bean>
16  <bean id="dicomViewerDataSource"                        
17      class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
18    <property name="targetDataSource">
19      <ref bean="dicomViewerDataSourceTarget" />
20    </property>
21  </bean>
22  <bean id="dicomViewerHibernateSessionFactory"
23      class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
24    <property name="dataSource">
25      <ref bean="dicomViewerDataSource" />
26    </property>
27  </bean>
28  <bean id="dicomViewerSessionFactory"               
29      class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl">
30    <property name="sessionFactoryImplementor">
31      <ref bean="dicomViewerHibernateSessionFactory" />
32    </property>
33  </bean>
34  <bean id="dicomViewerTransactionManager"
35      class="org.springframework.orm.hibernate3.HibernateTransactionManager">         
36    <property name="dataSource">
37      <ref bean="dicomViewerDataSource" />
38    </property>
39    <property name="sessionFactory">
40      <ref bean="dicomViewerHibernateSessionFactory" />
41    </property>
42  </bean>
43</beans>