掲示板

NoSuchMethodError from Liferay DXP 7 Service Builder

thumbnail
7年前 に Julian Jupiter によって更新されました。

NoSuchMethodError from Liferay DXP 7 Service Builder

New Member 投稿: 12 参加年月日: 17/03/24 最新の投稿
This is actually a secondary question to my Stackoverflow question which has been answered. Please refer to the link.

After successfully creating Service Builder with empty entity, I created my custom POJO model inside API. At first, I created two (2) methods, something like
getAllMembers()
and
getMemberById()
. The first method was working but the second one was not. I'm sure both methods were existing both in api (interface, util) and service after running
buildService
task on Gradle. My portlet on a separate module was able to call these methods, no red underline. Both modules were successful in build. But, during runtime, error occurred:
com.liferay.portal.kernel.portlet.PortletContainerException: com.liferay.portal.kernel.portlet.PortletContainerException: javax.servlet.ServletException: java.lang.NoSuchMethodError: ...


I renamed my methods to something (getAllMembers() to getMembership(), etc.) I think would not affect the service, no changes to logic. After build, none of the methods has been working. All of them are getting
java.lang.NoSuchMethodError
error.

I could not find any solution so I'm hoping someone would help me. Thank you.
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: NoSuchMethodError from Liferay DXP 7 Service Builder

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
There's an issue with empty entities that prevents ServiceBuilder from binding correctly.

I believe the answer is to your issue is addressed here: https://issues.liferay.com/browse/LPS-66607
thumbnail
6年前 に Julian Jupiter によって更新されました。

RE: NoSuchMethodError from Liferay DXP 7 Service Builder

New Member 投稿: 12 参加年月日: 17/03/24 最新の投稿
Thank you.

I've got another problem.
This is about calling XXXLocalService. Using @Reference and XXXLocalServiceUtil won't let module/porlet deploy. So I ended up:

private XXXLocalService xxxLocalService;


Inside a method:

xxxLocalService = new XXXLocalServiceImpl();


But, I'm getting this error:

Error during instantiation of the implementation object java.lang.NoClassDefFoundError: xx/xx/xx/xx/service/XXXLocalService


I don't understand because the service and api modules are included in build.gradle of the MVC Porlet and there is no red line indicating it can't find the class. Also, the module build is successful, only in deployment that it gets problem.

Thank you.
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: NoSuchMethodError from Liferay DXP 7 Service Builder

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Julian Jupiter:
This is about calling XXXLocalService. Using @Reference and XXXLocalServiceUtil won't let module/porlet deploy. So I ended up:

private XXXLocalService xxxLocalService;


Inside a method:

xxxLocalService = new XXXLocalServiceImpl();



This is your problem: These classes are not separated in different bundles just for fun: Your portlet only needs a dependency on the API, not the implementation (because you can swap that out). If the use of @Reference leads to deployment issues, you should fix the deployment issues (typically dependencies) rather than changing your code, breaking the modularity.
thumbnail
6年前 に Julian Jupiter によって更新されました。

RE: NoSuchMethodError from Liferay DXP 7 Service Builder

New Member 投稿: 12 参加年月日: 17/03/24 最新の投稿
Okay.

What I fail to understand is sometimes it (referencing directly XxxLocalService and XxxLocalServiceImpl) works, sometimes it does not even without changing code. I'm forced to use this way 'cause I could not find any solution when using @Reference; there is not a single error log in the console, the module is active as shown on Gogo shell but it won't appear on any Application categories of the Liferay.

Using @Reference, here is my code:
@Reference // I also tried with (unbind = "-")
	protected void setXxxLocalService(XxxLocalService xxxDetailsLocalService) {
		_xxxDetailsLocalService = xxxDetailsLocalService;
	}
	
	private XxxDetailsLocalService _xxxDetailsLocalService;

The build.gradlefile of my portlet is:
dependencies {
	compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
	compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
	compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
	compileOnly group: "javax.servlet", name: "servlet-api", version: "2.5"
	compileOnly group: "jstl", name: "jstl", version: "1.2"
	
	compile group: "org.osgi", name: "org.osgi.service.component.annotations", version :"1.3.0"
	
	compile project(":modules:xxx-details:xxx-details-api")
	compile project(":modules:xxx-details:xxx-details-service")
}

I also tried XxxLocalServiceUtil (I've raed it's an old way), the issue is the same as @Reference.

I'm inclined to using @Reference as this is preferred one on Liferay documentation. Thanks in advance for more help.