论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Liferay 6.1 GA2 - ext-spring failed on external datasource [SOLVED] Christophe Cariou 2012年10月18日 上午9:27
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2012年10月16日 上午8:33
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月17日 上午2:48
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2012年10月17日 上午6:06
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Jack Bakker 2012年10月17日 上午6:25
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月17日 上午7:40
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Jack Bakker 2012年10月17日 下午1:44
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2012年10月17日 下午2:12
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月18日 上午6:41
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月18日 上午6:54
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2012年10月18日 上午8:19
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月18日 上午8:57
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2012年10月18日 上午9:14
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Christophe Cariou 2012年10月18日 上午9:26
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Konstantin Chudinov 2013年5月2日 上午11:44
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2013年7月23日 下午7:21
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Jack Bakker 2013年7月23日 下午7:32
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2013年7月24日 上午6:08
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Jack Bakker 2013年7月23日 下午10:06
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource David H Nebinger 2013年7月24日 上午6:17
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource Jack Bakker 2013年7月24日 上午8:09
Christophe Cariou
Liferay 6.1 GA2 - ext-spring failed on external datasource [SOLVED]
2012年10月18日 上午9:27
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Hi,

I Have a plugin that combine a Service Builder made API and a Vaadin portlet (in only one war).

The service builder part has an external datasource defined in classe/META-INF/ext-spring.xml by this way :
 1
 2<?xml version="1.0"?>
 3
 4<beans
 5    default-destroy-method="destroy"
 6    default-init-method="afterPropertiesSet"
 7    xmlns="http://www.springframework.org/schema/beans"
 8    xmlns:aop="http://www.springframework.org/schema/aop"
 9    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
11>
12
13       <!-- Overrides -->
14   
15       <bean id="basePersistence" abstract="true">
16        <property name="dataSource" ref="oberDataSource" />
17        <property name="sessionFactory" ref="oberSessionFactory" />
18    </bean>
19   
20    <bean id="transactionAdvice" class="org.springframework.transaction.interceptor.TransactionInterceptor">
21        <property name="transactionManager" ref="oberTransactionManager" />
22        <property name="transactionAttributeSource">
23            <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource">
24                <constructor-arg>
25                    <bean class="com.liferay.portal.spring.annotation.PortalTransactionAnnotationParser" />
26                </constructor-arg>
27            </bean>
28        </property>
29    </bean>
30    
31    
32         
33    <!-- Custom beans -->
34    <bean id="oberDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
35       <property name="targetDataSource">
36           <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
37               <property name="propertyPrefix" value="jdbc.ober." />
38           </bean>
39       </property>
40       </bean>
41   
42    <bean id="oberHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortalHibernateConfiguration" lazy-init="true">
43        <property name="configurationClass">
44            <value>org.hibernate.cfg.Configuration</value>
45        </property>
46        <property name="dataSource">
47            <ref bean="oberDataSource" />
48        </property>
49         <property name="mappingResources">
50            <list>
51                <value>./META-INF/portlet-hbm.xml</value>
52            </list>
53        </property>
54    </bean>
55   
56    <bean id="oberTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
57        <property name="dataSource">
58            <ref bean="oberDataSource" />
59        </property>
60        <property name="sessionFactory">
61            <ref bean="oberHibernateSessionFactory" />
62        </property>
63    </bean>
64
65    <bean id="oberSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
66        <property name="sessionFactoryImplementor">
67            <ref bean="oberHibernateSessionFactory" />
68        </property>
69    </bean>


This plugin work fine on a liferay 6.0.6 or even 6.0.5.

As I'm upgrading to 6.1.1 GA2, I've rebuild all the plugin with sdk6.1, with Liferay IDE 1.6.

Now, when I deploy my plugin, or even restart my Liferay 6.1.1 I've this error :
 1
 2...
 3Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oberHibernateSessionFactory' defined in ServletContext resource [/WEB-INF/classes/META-INF/ext-spring.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist
 4    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
 5    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
 6    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
 7    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
 8    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 9    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
10    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
11    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
12    ... 151 more
13Caused by: java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist
14    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
15    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:677)
16    at com.liferay.portal.spring.hibernate.PortalHibernateConfiguration.buildSessionFactory(PortalHibernateConfiguration.java:65)
17    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
18    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
19    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
20    ... 158 more
21...


The root cause is : java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist

After some tests, it seems that my META-INF folder is not in the known classpath for my spring context.
I made a test putting portlet-hbm.xml in ROOT/WEB-INF/classe/META-INF, and then I haven't got this error (but others later, due to the lack of all the java classes that are still in my plugin war).

So it looks like there something changed between Liferay 6.0x and 6.1.1, and i suspect this : http://issues.liferay.com/browse/LPS-29103

I tried some changes in the web.xml file of my plugin but without success.

Has anybody encounter this trouble and find a work around ?
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月16日 上午8:33
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

I'm using Vaadin and SB, but I keep my Vaadin portlet separate from a standard SB portlet and things seem to work well in that configuration...

I haven't tried doing them in the same war file, but I'd guess that most of the issue is going to be getting the web.xml squared away so all of the appropriate filters and listeners are defined properly.
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 上午2:48
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Thank you David.

I'm agree : separating Service and GUI is a good practice, and, as you say, merging the two in a single plugin can lead to bad injection in the web.xml listeners declarations.

Just one (or more) things :
- You said that you deploy your Services in a portlet plugin. Not an ext-plugin. Is it right ?
- In that case, are you using external datasource ? or do you manage schemas as you suggest in this post : Support Catalog and Schema...
- Did you deploy on LIferay 6.1.1 GA2?
- Can't I have a sample of your ext-spring.xml ?



Christophe
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 上午6:06
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

I have a separate portlet plugin based upon the Liferay MVC portlet type (it's really blank) that I keep my services in. Since it's Liferay MVC (and since I'm not using it), all of the correct things are injected in the right places to make SB happy.

I'm still running 6.0 (EE sp 2, actually, but would still be the same for 6.0.6). We're not going to do the 6.1 upgrade until Liferay goes to 6.1.

I am using an external data source for my SB, but also use the catalog/schema changes I mentioned. The external data source is to my SqlServer database, and the catalog/schema changes allow me to access all of my entities there.

My sample from my ext-spring.xml would be:

 1    <bean id="mobileC3P0DataSource" lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" />
 2    <bean id="mobileDataSource" lazy-init="true" class="com.csi.util.PropertiesBasedC3P0DataSource">
 3        <property name="properties" ref="dataServicesProperties" />
 4        <property name="prefix" value="mobile" />
 5        <property name="comboPooledDataSource" ref="mobileC3P0DataSource" />
 6    </bean>
 7    <bean id="mobileHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
 8        <property name="dataSource" ref="mobileDataSource" />
 9         <property name="hibernateProperties">
10            <bean class="com.csi.util.PropertiesWrapper" >
11                <property name="typedProperties" ref="dataServicesProperties" />
12                <property name="propertyPrefix" value="mobile" />
13            </bean>
14        </property>
15    </bean>
16    <bean id="mobileSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
17        <property name="dataSource" ref="mobileDataSource" />
18        <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
19        <property name="sessionFactoryImplementor" ref="mobileHibernateSessionFactory" />
20    </bean>


This is a basic set of beans for defining your own data source within the ext-spring.xml file. I've got a number of classes extending the Liferay classes so I can inject properties from a properties file (I don't like using EL injection because a missing property causes exceptions to be thrown), but otherwise it's not that different from the other examples you find on the web...
Jack Bakker
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 上午6:25
答复

Jack Bakker

等级: Liferay Master

帖子: 606

加入日期: 2010年1月3日

最近的帖子

I use the same approach as David

one MVCPortlet for services ; and then various seperate Vaadin and other MVCPortlets

but now I am curious about Davids use of c3p0 for this and need to try it

David are u able to provide your dataServicesProperties references with the sensitive bits altered for the sake of the innocent ?
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 上午7:40
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Thanks all.

I'm going to test this by cutting my plugin in two separates ones (portlet SB/MVC and portlet Vaadin)

I'll feedback when done.

Christophe
Jack Bakker
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 下午1:44
答复

Jack Bakker

等级: Liferay Master

帖子: 606

加入日期: 2010年1月3日

最近的帖子

ah I see: CSI is Contact Solutions Inc. which is your company

so com.csi.util.PropertiesWrapper is yours ; ok, thanks
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月17日 下午2:12
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

Jack Bakker:
ah I see: CSI is Contact Solutions Inc. which is your company

so com.csi.util.PropertiesWrapper is yours ; ok, thanks


Yeah, I actually have a bunch of external data sources that I use in my data services portlet, but only one properties file. I prefix the properties with a fixed string, i.e. "mobile", and my properties wrapper can return a fixed property name, i.e. "jdbc.url" that my standard implementation wants but will actually end up using the "mobile.jdbc.url" from the properties file.

This way I can have "mobile.jdbc.url" and "reporting.jdbc.url" in the properties file but my implementation classes don't specifically need to know about an exact property to look for...

Comes in quite handy, especially in cases like I have locally...
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午6:41
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Yes : "Divide to conquer" was the good stragegy. Thank you.

I splitted my plugin in two separate ones :
- Portlet MVC with Service Builder inside
- Portlet Vaadin with UI.

My ext-spring.xml is shorted right now (will see if it needs some more stuff) and it works :
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3
 4<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">
 5
 6    <bean id="oberDataSource" lazy-init="true" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
 7        <property name="targetDataSource">
 8            <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
 9                <property name="propertyPrefix" value="jdbc.ober." />
10            </bean>
11        </property>
12    </bean>
13
14    <bean id="oberHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
15        <property name="dataSource" ref="oberDataSource" />
16    </bean>
17   
18    <bean id="oberSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
19        <property name="dataSource" ref="oberDataSource" />
20        <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
21        <property name="sessionFactoryImplementor" ref="oberHibernateSessionFactory" />
22    </bean>
23   
24</beans>


I also moved the service.jar of the service builded plugin to tomcat lib/ext.

Deployment of both plugins succeed and I can see that query reach the good datasource.

But, now I encounter some other trouble because my UI/Vaadin code was referencing modelImpl classes that I can reach.

Should I change my logic in order to not using this classes from my UI, and declaring new methods in my Services ?

For example, instead of using :
myLocalService.addObect(beanImpl)
using something like
myLocalService.addObject(property1, property2, ....)

Or can I copy my modelImpl classes from the ServiceBuilder plugin to the UI Plugin ?
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午6:54
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Moreover, all the samples I found (even the one from official Liferay training) use the modelImpl classes... but I don't see how to respect this pattern when service and UI are in separates plugins (unless deploying my services as an ext-plugin perhaps...)
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午8:19
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

No, from the vaadin side you need to stick to the service jar.

So you'll use the XxxLocalServiceUtil static classes to access your entities.

So if you were using myLocalService.addObject() in your vaadin code, you'd now be using MyLocalServiceUtil.addObject().

This is different from what you'll do inside of your service implementation classes, where you will still use the myLocalService.addObject() just as you did before.
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午8:57
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Excuse me, i mistyped my sample.

I'm agree with you. I use MyLocalServiceUtil service class in the Vaadin portlet (was already like that before I split in two plugins).

Now, my trouble is just that, before the separation, I was using ObjectImpl class as parameter for MyLocalServiceUtil methods. And now this class is no longer available (because not known in service.jar).

example, in some vaadin side code :

ObjectLocalServiceUtil.updateObject(object) where object has been instancied from ObjectImpl, that is a result of the service building for a final database item objectTable.


The way I'm going to solve this is to replace this client service call by a new one :

ObjectLocalServiceUtil.updateObject(arg1, arg2, arg3...) providing the service with all the necesssary datas to build an Object

and so, in ObjectLocalServiceUtilImpl I declare a new method :
 1
 2updateObject (arg1, arg2.....)
 3{
 4  Object object = objectPersistence.create(counterLocalService.increment(Object.class.getName()));
 5  object.setArg1(arg1);
 6  object.setArg2(arg2);
 7   ...
 8  objectPersistence.update(object)
 9}


and after regenerate all the stuff with service builder (Interfaces, service.jar...).

I'm just disappointed that I can't use the ObjectImpl classes. I'm forced to declare some POJOs in my vaadin portlet to transport my datas that are very similar to the ones generated by SBuilder.

But after looking Liferay sources, that's the way Liferay is made itself.... so it seems to be the correct way ...
...unless you have an alternative, giving the ability to reuse the Model stack generated by ServiceBuilder from client Portlet?

Anyway, thanks a lot David for your help.

Christophe
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午9:14
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

Okay, sorry for the disconnect, but here goes.

Let's start with a simple entity in your service.xml file:

 1
 2<service-builder package-path="com.example">
 3    <namespace>TEST</namespace>
 4    <entity name="MyObject" local-service="true" remote-service="false">
 5        [...]
 6        <column name="name" type="String" />
 7        <column name="value" type="int" />
 8    </entity>
 9</service-builder>


When you build your services, you'll have a com.example.service.impl.MyObjectLocalServiceImpl class.

Let's say you want to create a utility function to add a new entity to the database. In the MyObjectLocalServiceImpl class, you'd add the following method:

 1
 2public MyObject addObject(final String name, final int value) {
 3    // create a new instance
 4    MyObject obj = createMyObject(0);
 5
 6    // set the values
 7    obj.setName(name);
 8    obj.setValue(value);
 9
10    // save and return the new instance
11    return addMyObject(obj);
12}


Note there is no MyObjectImpl classes in play here, you only want to stick to the interfaces.

Now you rebuild your services (so the new method is added).

Switching over to your vaadin code, when it comes time to do the add you can invoke the method as such:

 1
 2    ...
 3
 4    // find the values for name and value, i.e. from vaadin components you have
 5
 6    // add the object
 7    MyObject obj = MyObjectLocalServiceUtil.addObject(name, value);
 8
 9    // do whatever with the created instance


Again, here you're just coding against the service jar interfaces. You're not doing anything with MyObjectImpl classes in any way, shape, or form.

The key here is that you never use impl classes directly, not in service builder generated code, not in your vaadin code, not anywhere. You are always coding against the interfaces that are defined in the service jar. Period.
Christophe Cariou
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2012年10月18日 上午9:26
答复

Christophe Cariou

等级: Junior Member

帖子: 44

加入日期: 2007年10月1日

最近的帖子

Thanks for the tuto.

We are agree and that's a way I'm going to do it.

Solved for me.

Christophe
Konstantin Chudinov
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年5月2日 上午11:44
答复

Konstantin Chudinov

等级: Junior Member

帖子: 43

加入日期: 2013年4月23日

最近的帖子

fluently looked through this thread, i didn't find the solution... why spring doesn't see META-INF/portlet-hbm.xml?
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月23日 下午7:21
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

Sure, Jack, but we have multiple portlets that use their own properties and sometimes the keys overlap.

Plus it's easier to deploy the project w/ properties contained within as we don't always trust our ops folks to correctly type in the values we need emoticon
Jack Bakker
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月23日 下午7:32
答复

Jack Bakker

等级: Liferay Master

帖子: 606

加入日期: 2010年1月3日

最近的帖子

woops, accidentally deleted my post..., copying it here from email

David, Have you thought of using something like the below to get from portal-ext.properties? (except for c3p0 properties ?)

String driverClassName = PropsUtil.get("jdbc.mydb.driverClassName");
String url = PropsUtil.get("jdbc.mydb.url");
String userName = PropsUtil.get("jdbc.mydb.username");
String password = PropsUtil.get("jdbc.mydb.password");

Also, where is your com.csi.util. package ? it isn't in a global classpath I hope...
Jack Bakker
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月23日 下午10:06
答复

Jack Bakker

等级: Liferay Master

帖子: 606

加入日期: 2010年1月3日

最近的帖子

Drawing on several sources, here is an approach connecting to a second database:

ext-spring.xml
 1
 2<?xml version="1.0"?>
 3<beans xmlns="http://www.springframework.org/schema/beans"
 4    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
 5    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 7
 8    <aop:config>
 9        <aop:pointcut id="transactionOperation" expression="bean(*Service.impl)" />
10        <aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionOperation" />
11    </aop:config>
12   
13    <bean id="basePersistence" abstract="true">
14        <property name="dataSource" ref="mydbDataSource" />
15        <property name="sessionFactory" ref="mydbSessionFactory" />
16    </bean>
17   
18    <bean id="transactionAdvice" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
19        <constructor-arg value="com.liferay.portal.spring.transaction.TransactionInterceptor" />
20        <constructor-arg>
21            <map>
22                <entry key="platformTransactionManager" value-ref="mydbTransactionManager" />
23                <entry key="transactionAttributeSource" value-ref="transactionAttributeSource" />
24            </map>
25        </constructor-arg>
26    </bean>
27   
28
29   
30    <bean id="mydbHibernateSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
31        <constructor-arg value="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" />
32        <constructor-arg>
33            <map>
34                <entry key="dataSource" value-ref="mydbDataSource" />
35            </map>
36        </constructor-arg>
37    </bean>
38    <bean id="mydbSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
39        <constructor-arg value="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl" />
40        <constructor-arg>
41            <map>
42                <entry key="dataSource" value-ref="mydbDataSource" />
43                <entry key="sessionFactoryClassLoader" value-ref="portletClassLoader" />
44                <entry key="sessionFactoryImplementor" value-ref="mydbHibernateSessionFactory" />
45            </map>
46        </constructor-arg>
47    </bean>
48    <bean id="mydbTransactionManager" class="com.liferay.portal.kernel.util.InfrastructureUtil" factory-method="getTransactionManager" />
49   
50   
51    <bean id="mydbDataSource" class="ca.iable.util.PropertiesBasedDataSource" factory-method="getDataSource">
52        <constructor-arg value="jdbc.mydb."/> 
53    </bean>   
54   
55</beans>


service.xml
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 4<service-builder package-path="ca.iable.services">
 5    <author>jbakker</author>
 6    <namespace>services</namespace>
 7
 8    <entity name="Global" table="global" data-source="mydbDataSource"
 9        local-service="true" remote-service="true" session-factory="mydbSessionFactory"
10        tx-manager="mydbTransactionManager">
11
12        <!-- PK fields -->
13
14        <column name="global_id" db-name="global_id" type="int"
15            primary="true" id-type="sequence" id-param="global_id_seq" />
16
17        <!-- Other fields -->
18
19        <column name="name" type="String" />
20        <column name="value" type="String" />
21
22        <finder name="Name" return-type="Global" unique="true">
23            <finder-column name="name" />
24        </finder>
25    </entity>
26   
27    <entity name="Subscribe" table="subscribe" data-source="mydbDataSource"
28        local-service="true" remote-service="true" session-factory="mydbSessionFactory"
29        tx-manager="mydbTransactionManager">
30
31        <!-- PK fields -->
32
33        <column name="subscribe_id" db-name="subscribe_id" type="int"
34            primary="true" id-type="sequence" id-param="subscribe_id_seq" />
35       
36        <column name="crea_ts" db-name="crea_ts" type="Date" />
37        <column name="modi_ts" db-name="modi_ts" type="Date" />
38        <!-- Other fields -->
39
40        <column name="email" type="String" />
41        <column name="source" type="String" />
42
43        <finder name="Email" return-type="Subscribe" unique="true">
44            <finder-column name="email" />
45        </finder>
46    </entity>
47   
48</service-builder>


PropertiesBasedDataSource.java
 1
 2package ca.iable.util;
 3
 4import com.liferay.portal.kernel.dao.jdbc.DataSourceFactoryUtil;
 5import com.liferay.portal.kernel.log.Log;
 6import com.liferay.portal.kernel.log.LogFactoryUtil;
 7import com.liferay.portal.kernel.util.PropsUtil;
 8import javax.sql.DataSource;
 9
10public class PropertiesBasedDataSource {
11
12    private PropertiesBasedDataSource() {
13    };
14
15    public static DataSource getDataSource(String propertyPrefix) {
16        String driverClassName = PropsUtil.get(propertyPrefix
17                + "driverClassName");
18        String url = PropsUtil.get(propertyPrefix + "url");
19        String userName = PropsUtil.get(propertyPrefix + "username");
20        String password = PropsUtil.get(propertyPrefix + "password");
21
22        DataSource _dataSource = null;
23        try {
24            _dataSource = DataSourceFactoryUtil.initDataSource(driverClassName,
25                    url, userName, password);
26        } catch (Exception e) {
27            _log.error("unable to get datasource using prefix "
28                    + propertyPrefix + " in portal-ext.properties");
29        }
30        return _dataSource;
31    }
32
33    private static Log _log = LogFactoryUtil
34            .getLog(PropertiesBasedDataSource.class);
35
36}


portal-ext.properties
 1
 2jdbc.default.driverClassName=org.postgresql.Driver
 3jdbc.default.url=jdbc:postgresql://db.iable.ca/lportal_iable61?
 4useUnicode=true&amp;characterEncoding=UTF-8
 5jdbc.default.username=lportal_user
 6jdbc.default.password=mypassword
 7
 8jdbc.mydb.driverClassName=org.postgresql.Driver
 9jdbc.mydb.url=jdbc:postgresql://db.iable.ca/mydb?
10useUnicode=true&amp;characterEncoding=UTF-8
11jdbc.mydb.username=lportal_user
12jdbc.mydb.password=mypassword
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月24日 上午6:08
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

Jack Bakker:
Also, where is your com.csi.util. package ? it isn't in a global classpath I hope...


No, it's not. We have a single jar that has home-made utility classes. The jar is deployed using an EXT plugin and pulled into projects that depend upon it using the liferay-plugin-package.properties file...
David H Nebinger
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月24日 上午6:17
答复

David H Nebinger

等级: Liferay Legend

帖子: 7080

加入日期: 2006年9月1日

最近的帖子

Jack Bakker:
portal-ext.properties
 1
 2jdbc.default.driverClassName=org.postgresql.Driver
 3jdbc.default.url=jdbc:postgresql://db.iable.ca/lportal_iable61?useUnicode=true&amp;characterEncoding=UTF-8
 4jdbc.default.username=lportal_user
 5jdbc.default.password=mypassword
 6
 7jdbc.mydb.driverClassName=org.postgresql.Driver
 8jdbc.mydb.url=jdbc:postgresql://db.iable.ca/mydb?useUnicode=true&amp;characterEncoding=UTF-8
 9jdbc.mydb.username=lportal_user
10jdbc.mydb.password=mypassword


Okay, this is a general difference that we have, but no big deal...

I prefer to keep the liferay system properties (the ones in portal-ext.properties) just for liferay needs. For our own custom portlets that require properties, I prefer that they are maintained outside of the liferay properties as completely separate entities.

This is probably due to paranoia on my part, but once I have a working portal-ext.properties file I don't want anyone tampering it for any reason. If you get a new developer that creates a new portlet using a 'new' property, say "upgrade.processes" and gets the value put into portal-ext.properties the Liferay environment breaks...

Using isolated properties files, the developer's new portlet just works and the Liferay environment doesn't get a faulty overridden value of "upgrade.processes"...
Jack Bakker
RE: Liferay 6.1 GA2 - ext-spring failed on external datasource
2013年7月24日 上午8:09
答复

Jack Bakker

等级: Liferay Master

帖子: 606

加入日期: 2010年1月3日

最近的帖子

I hope my post will help other small-fries like me and I learned a lot digging through Liferay source and the META-INF/*.xml files generated from service builder but still need to look at c3p0 properties like you have already done to introduce

approach to what is global and what is portletLocal or portletSetLocal will be an ongoing I think ; bundles ?