2

Whereas I had no problem with the Service Builder in Liferay 6.2, I meet a blocking issue in Liferay 7 when I am building service to generate my first Finder Util class. When I discover that, I even decided to start from scratch a project, the problem is still here. Even with the official doc, nothing works.

Does someone has any idea to help me ?

Here is the complete description for my last test in Eclipse Mars :

  1. Create a new Liferay Workspace
  2. Create a new Liferay Project Module Service Builder
  3. Create a foo object in service.xml
  4. Build services (class are well generated)
  5. Create manually a FooFinderImpl class in the persistence.impl package
  6. Build services
    The FooFinder interface is well generated but the FooFinderUtil class is not generated.
  7. Add some methods in the FooFinderImpl class
  8. Build services
  9. Nothing new

Thank you for you help.

Vincent

Vincent
  • 139
  • 1
  • 13

2 Answers2

2

When you build the service there are some properties in build.gradle so if you want to generate the Util class has to set osgiModule to false.

buildService {
    apiDir = "../foo-api/src/main/java"
    osgiModule = false
    propsUtil = "com.liferay.docs.foo.service.util.PropsUtil"
}

Otherwise if you want to use osgi you can retrive the finder this way

@Reference
private volatile FooFinder fooFinder;

or

@Reference(unbind = "-")
protected void setFooFinder(
        FooFinder fooFinder) {

    _fooFinder = fooFinder;
}

private FooFinder _fooFinder;

for more info see liferay-docs https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/finding-and-invoking-liferay-services

exampel on github http://github.com/bruinen/liferay-services-example

Romeo Sheshi
  • 901
  • 5
  • 7
  • Thank you very much for your answer ! Your first proposition solved the problem but I would keep OSGI. So, I've just tried the second one but my finder is null, do I have to declare it anywhere else ? – Vincent Dec 02 '16 at 12:59
  • can you try the other code i add in edit. The reference take takes the service implementation of the interface so you just have to deploy the osgi bundle foo-service and foo-api. try to import the package in the bundle you are using the finder `Import-Package: com.liferay.foo.service` . – Romeo Sheshi Dec 02 '16 at 13:23
  • Ok, my finder is still null with the third solution but I am going to read the Liferay documentation that you've mentionned. I give you news. – Vincent Dec 02 '16 at 13:44
  • if I use FooFinder in my FooLocalServiceImpl with the "@Reference" annotation, can I call the FooLocalServiceImpl class method through FooLocalServiceUtil or do I need to declare a the FooLocalService with the "@ServiceReference" annotation in my portlet module ? – Vincent Dec 02 '16 at 15:16
  • I think the two way will work the same because the Util class use serviceTracker to get the implementation so It will be the same logic of @Reference – Romeo Sheshi Dec 02 '16 at 15:20
  • My finder is still null with all these solutions unfortunately – Vincent Dec 02 '16 at 15:37
  • I try to make a test in local – Romeo Sheshi Dec 02 '16 at 15:38
  • Thank you very much for your help – Vincent Dec 02 '16 at 15:39
  • hi i make a test and it works with `@Reference private volatile FooFinder fooFinder;` i commit the example to git https://github.com/bruinen/liferay-services-example – Romeo Sheshi Dec 02 '16 at 16:44
  • Last point (sorry to bother you again), I would like to add the service layer between the portlet and the finder class. How do you manage this ? Because I have again null finder when I add this service layer ?
    Details : In portlet, the "@Reference" works to declare the FooLocalService interface. In the FooLocalServiceImpl, the "@Reference" doesn't work to declare the FooFinder interface, the interface is null. Do you have an idea ?
    – Vincent Dec 06 '16 at 11:31
  • Just use the getter from the BaseImpl getFooFinder() without settting the reference – Romeo Sheshi Dec 06 '16 at 12:35
  • 1
    Nice ! Thank you for the time you've spent ! Have a nice day ! – Vincent Dec 06 '16 at 13:09
  • nice to help, you too! – Romeo Sheshi Dec 06 '16 at 13:12
0

From https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/custom-sql

Note: In previous versions of Liferay Portal, your finder methods were accessible via -FinderUtil utility classes. Finder methods are now injected into your app’s local services, removing the need to call finder utilities.

You should now be able to directly call your finder method in the service layer: fooFinder.findBy...