0

I have implemented a functional Liferay service using service builder and I want to call a method on the -LocalServiceUtil class just as soon as I possibly can. This is a task I wish to perform when the service starts and also when the service is redeployed.

Even though all the methods on the -LocalServiceUtil class are static, they will throw a BeanLocatorException if they are called too soon.

com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set for servlet context portal-navigation-impl

Is there any way to call a method on the -LocalServiceImpl instance or otherwise so that I can do this?

Thank you

Yoshiya
  • 452
  • 5
  • 17

1 Answers1

2

As you speak about the initialization order: I'm not 100% sure about this, but I'd write a startup action. This gets run everytime a hook (or plugin) starts up - including a redeploy. Sounds like what you want - and if the initialization order works, this is your solution.

Otherwise: Create a separate hook that's dependent on the one that you're currently using. That will be restarted as well, but only run once the hook providing the *-LocalService did already start up. (dependency is declared in liferay-plugin-package.properties, with the key required-deployment-context - this is from memory - somebody correct me if I'm wrong.)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • That is some good information, thanks for responding. I tried out the startup action, which is helpful - it fires when I start up Liferay, but it does not fire when I hot-deploy my WAR. – Yoshiya Jan 11 '16 at 17:15
  • It doesn't? I'd expect it to. It can only fire once the hook is deployed, and I always expected it to fire every time the hook deploys. Not to say that this is guaranteed - unfortunately I can't check this right now – Olaf Kock Jan 11 '16 at 17:28
  • After viewing your comment above I went back and rechecked. It seems that when I am running using JRebel it does not get called when I hot deploy (a real hot-deploy, not just a JRebel class reload). But when I disable the JRebel agent, the startup action listener gets called when I hot deploy. I do not know why that would be... – Yoshiya Jan 11 '16 at 20:48
  • ok - JRebel in the game and everything might change. Good to know that my memory isn't too bad :) Thanks for reporting back – Olaf Kock Jan 11 '16 at 21:21