留言板

Using LocalServiceUtils in Liferay 7

thumbnail
Daniel Breitner,修改在7 年前。

Using LocalServiceUtils in Liferay 7

Regular Member 帖子: 105 加入日期: 08-7-16 最近的帖子
Hi everyone,

we are starting our first Liferay 7 project and I already got stuck.

I would like to create a portlet which reads the Data from the DDMContent Table.
Luckily there is the DDMContentLocalServiceUtil.

I am struggeling on how to actually use it.

I added it to the build.gradile file like this:

	compileOnly group: "com.liferay", name: "com.liferay.dynamic.data.mapping.api", version: "3.1.0"


I added it to the bnd.bnd file like this :

Import-Package: com.liferay.dynamic.data.mapping.api;version=3.1.0


And then I included in my portlet class like this:

@Reference
	public void setContentLocalServiceUtil(DDMContentLocalServiceUtil contentLocalServiceUtil) {
		this.contentLocalServiceUtil = contentLocalServiceUtil;
	}



The portlet compiles and starts to deploy but I never get to the point where I can actually use it because it is never fully deployed.
There is no Exception and there is no hint on what I did wrong.

Is my version number correct ?
Do I need to add it to the bnd.bnd file ?
Who can help me out ?

Best regards,

Daniel
thumbnail
Olaf Kock,修改在7 年前。

RE: Using LocalServiceUtils in Liferay 7

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
The @Reference setter should not be for the *LocalServiceUtil, but for the *LocalService. The *LocalServiceUtil classes are purely for legacy portlets as they hide the dependency and only provide an indirection to call the service. With OSGi components, you should never call the *LocalServiceUtil classes any more.
thumbnail
Juan Gonzalez,修改在7 年前。

RE: Using LocalServiceUtils in Liferay 7

Liferay Legend 帖子: 3089 加入日期: 08-10-28 最近的帖子
Ouch, Olaf wrote when I was looking for some documentation :-).

Olaf is right, you can't have a reference to a service that hasn't been published. In this case, that service doesn't exist so that reference won't be ever met and your component (Portlet) won't ever be active.

Daniel, take a look at this examples in Developer Network to see this approach with examples: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/finding-and-invoking-liferay-services