留言板

Service Builder - Accessing Service from other portlets

thumbnail
Gaurav Vaish,修改在12 年前。

Service Builder - Accessing Service from other portlets

New Member 帖子: 12 加入日期: 10-11-14 最近的帖子
Hi,

I am trying to create a "core" service layer that can be used by various other portlets, in different projects.

As I understand, the "core"-service.jar and "core"-impl.jar both have to be in WEB-INF/lib of the "ROOT" so that it can be made available to all the portlets at the runtime.

However, I fail to achieve this...

If I use the above technique, I get the following error while starting the server:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayHibernateSessionFactory' defined in class path resource [META-INF/hibernate-spring.xml]: Cannot resolve reference to bean 'liferayDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayDataSource' defined in class path resource [META-INF/infrastructure-spring.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'targetDataSource' threw exception; nested exception is java.lang.IllegalArgumentException: 'targetDataSource' must not be null
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:558)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
	at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized(PortalContextLoaderListener.java:47)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:519)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)



-Gaurav
thumbnail
Shagul Khajamohideen,修改在12 年前。

RE: Service Builder - Accessing Service from other portlets

Liferay Master 帖子: 758 加入日期: 07-9-27 最近的帖子
The service jar needs to go in the tomcat/lib. All other implementation can stay within the portlet war that you are implementing the services. Also you need to make sure the service jar is not included in your portlet and present just under tomcat/lib.

Hopefully in the coming versions, we may have a better way to manage them.
OSGi
thumbnail
Volker Wurst,修改在12 年前。

RE: Service Builder - Accessing Service from other portlets

New Member 发布: 1 加入日期: 11-4-8 最近的帖子
I have a similar problem: I also want to access my service builder classes from another portlet.

According to the Liferay In Action book (chapter 3.5.2), I should just copy the generated jar file to the global classpath of Tomcat in order to make it accessible to other portlets...

When I start Tomcat, I get CLASS NOT FOUND error messages for the Impl and Util-classes.

When I build the service (via eclipse build-service), the generated ..service.jar does only contain the classes from the *service* directory. The -impl und -Util-classes from the src-directory are missing.

Am I missing something?
Ranvijay Singh,修改在12 年前。

RE: Service Builder - Accessing Service from other portlets

New Member 帖子: 15 加入日期: 11-6-3 最近的帖子
Hi,
I have similar issue and solve it ,by adding a new custom method in local method's service class, which simply return the plain object (Impl..) and Re-generate service again. Below is the sample code.

public SendReceiveGift getSendReceiveGiftInstance() {
SendReceiveGift sendReceiveGift = new SendReceiveGiftImpl();
return sendReceiveGift;
}

While calling this method in other portlet as.

SendReceiveGift sendReceiveGift= SendReceiveGiftLocalServiceUtil.getSendReceiveGiftInstance();