Reputation: 236
I am making a custom-sql appication. I made a service builder , created finder column,built and deployed it. Table created successfully. Now I made a *FinderImpl class manually and a custom-sql folder with necessary details and rebuilt the services. *Finder interface generated successfully. I implemented *Finder interface in *FinderImpl class, then rebuilt services but *FinderUtil not generated. I ignored it as I could easily call *FinderImpl class' method directly. I created a custom method inside *FinderImpl class and rebuilt the service. I am calling this method inside *LocalServiceImpl and calling the method of *LocalServiceImpl through *LocalServiceUtil. But to my surprise I got the most common error-"NullPointerException".I debugged and found that getService() method of *LocalServiceUtil has value as null. Please tell me how to eradicate this error as I have been stuck throughout the day but could not resolve. So,please help. Thanx in advance.
Upvotes: 1
Views: 2389
Reputation: 308
I've been having the same issue getting a NullPointerException
when I add a EntityFinderImpl
class to my Service Builder.
I've just found that I need to add a Component annotation to my EntityFinderImpl
class:
@Component(
service = EntityFinder.class
)
public class EntityFinderImpl extends EntityFinderBaseImpl implements EntityFinder {
public List<Entity> findByDate(Date date) {
...
return dates;
}
}
This appears to occur as EntityLocalServiceBaseImpl class gets a @Reference
added point ing to the EntityFinder
, but that reference cannot be satisfied as there is no component to reference.
You can diagnose if this is the issue in a Gogo shell using the command:
ds:unsatistied
Or optionally:
ds:unsatisfied <bundleid>
You can also review the components and references that a bundle has using the Gogo command:
scr:list <bundleid>
Lastly, see also Liferay's Detecting Unresolved OSGi Components doc.
Upvotes: 2
Reputation: 931
you class finder declaration have to be
public class CustomUser2FinderImpl extends CustomUser2BaseFinderImpl implements CustomUser2Finder
When you build the service there are some properties in build.gradle so if you want to generate the FinderUtil class has to set osgiModule to false.
buildService {
osgiModule = false
}
Otherwise if you want to use osgi you can retrive the finder this way
@Reference
private volatile CustomUser2Finder customUser2Finder;
Upvotes: 0