RE: RE: NoSuchMethodError from service builder

Scarletake Bwi, modified 3 Years ago. Expert Posts: 327 Join Date: 12/20/10 Recent Posts

hi 

i am using liferay 7.4 and service builder

there have 2 issues alway burder me.

when i writen a new method, and buildservice from -service, build from -api, deploy both.

sometimes, my other mvc-portlet using @Reference to call the method, it throws NoSuchMethodError.

the only way out is delete all in both modules and state of osgi, and restart server via clean. it will force all modules new.

how can i avoice this?

follows the first issue, another issue is, i have to install a jar from gogo shell, but after i delete state of osgi, i have to reinstall it again.

is there any way to make it always in there such like i copy the jar and put it in shielded-container-lib

thanks in advance.

thumbnail
Olaf Kock, modified 3 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

If you @Reference something, make sure that you'll never hold on to that reference for longer - e.g. store it exactly in the component that declares the dependencies, and (best case) pass it as parameter to any other methods and objects that need access to some service.

Scarletake Bwi, modified 3 Years ago. Expert Posts: 327 Join Date: 12/20/10 Recent Posts

Hi Olaf

thank you for reply. 

i did modify my build.gradle, with "compileOnly project" for both -api and -service. btw, if i did not, i cannot even compile. 

what is "never hold on to that reference for longer" mean? if you mean i will use it in a supper loop or sometime will keep it be hold-on, no, i just use it to get a value object with key.

@Reference will always work in mvc portlet, but in other object, such like some object extends from MessageListener, it won't work, i have to use xxxLocalServiceUtil.