RE: OSGI unsatisfied reference

thumbnail
Yan Paing, modified 6 Years ago. Regular Member Posts: 130 Join Date: 3/11/10 Recent Posts
Hi All,I tried to do custom finder method according to https://portal.liferay.dev/docs/7-2/appdev/-/knowledge_base/a/defining-a-custom-finder-method .  After that there is OSGI unsatisfied reference error is coming as per following. Any one please suggest how should i solve for the issue. I am using liferay 7.2 GA1. Thank you

Component Description: com.liferay.docs.guestbook.service.impl.GuestbookLocalServiceImpl
========================================================================================
Class:         com.liferay.docs.guestbook.service.impl.GuestbookLocalServiceImpl
Bundle:        120 (com.liferay.docs.guestbook.service:1.0.0)
Enabled:       true
Immediate:     false
Services:      [com.liferay.portal.aop.AopService]
Scope:         singleton
Config PID(s): [com.liferay.docs.guestbook.service.impl.GuestbookLocalServiceImpl], Policy: optional
Base Props:    (1 entry)
  model.class.name<String> = com.liferay.docs.guestbook.model.GuestbookComponent Configuration Id: 5043
--------------------------------
State:        UNSATISFIED REFERENCE
Config Props: (3 entries)
  component.id<Long> = 5043
  component.name<String> = com.liferay.docs.guestbook.service.impl.GuestbookLocalServiceImpl
  model.class.name<String> = com.liferay.docs.guestbook.model.Guestbook
References:   (total 7)
  - guestbookFinder: com.liferay.docs.guestbook.service.persistence.GuestbookFinder UNSATISFIED 1..1 static
    target=(*) scope=bundle
  - classNameLocalService: com.liferay.portal.kernel.service.ClassNameLocalService SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
  - counterLocalService: com.liferay.counter.kernel.service.CounterLocalService SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
  - guestbookEntryPersistence: com.liferay.docs.guestbook.service.persistence.GuestbookEntryPersistence SATISFIED 1..1 s
tatic
    target=(*) scope=bundle (no active bindings)
  - guestbookPersistence: com.liferay.docs.guestbook.service.persistence.GuestbookPersistence SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
  - resourceLocalService: com.liferay.portal.kernel.service.ResourceLocalService SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
  - userLocalService: com.liferay.portal.kernel.service.UserLocalService SATISFIED 1..1 static
    target=(*) scope=bundle (no active bindings)
g!
g!
thumbnail
Yan Paing, modified 6 Years ago. Regular Member Posts: 130 Join Date: 3/11/10 Recent Posts
Hi Everyone,Any suggestion? Thank you
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
So this line:

guestbookFinder: com.liferay.docs.guestbook.service.persistence.GuestbookFinder UNSATISFIED 1..1 static target=(*) scope=bundle


This tells you that your GuestbookLocalServiceImpl has an @Reference dependency on a GuestbookFinder, but it is not finding one.

So this points to your GuestbookFinder not starting and/or not registering. Do you have this corresponding info on the GuestbookFinder?  Can you share some or all of your GuestbookFinder class?
thumbnail
Yan Paing, modified 6 Years ago. Regular Member Posts: 130 Join Date: 3/11/10 Recent Posts
Hi David,
Please see the attached for all source code.

Yes, correct and agree that GuestbookLocalServiceImpl has an @Reference dependency on a GuestbookFinder and can't find.

guestbookFinder.findByEntryNameEntryMessageGuestbookName(entryName, entryMessage,guestbookName, begin, end); is calling within GuestbookEntryLocalServiceImpl .

Please suggest how should i fix it. I am using liferay 7.2 GA1. I also attached web portlet as well. Thank you
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
You cannot @Reference a class that is not itself an @Component.

Your GuestbookFinderImpl is not an @Component, so OSGi has nothing to inject.
thumbnail
Yan Paing, modified 6 Years ago. Regular Member Posts: 130 Join Date: 3/11/10 Recent Posts
Thank you so much David,
Firstly i tried to put @Component in GuestbookFinderImpl but it is also fail.  Finally i changed following without using @Reference and it is working.

From GuestbookFinderImpl class
---------------------------------------------------
String sql = CustomSQLUtil.get(
//                String sql = _customSQL.get(
                    getClass(),
                    FIND_BY_ENTRYNAME_ENTRYMESSAGE_GUESTBOOKNAME);
//        @Reference
//        private CustomSQL _customSQL;

From build.gradle
-------------------------------
compileOnly group: 'com.liferay', name: 'com.liferay.portal.dao.orm.custom.sql', version: '1.0.22'
runtime group: 'com.liferay', name: 'com.liferay.portal.dao.orm.custom.sql', version: '1.0.22'

from bnd.bnd
-------------------------------
Import-Package: \ *
-includeresource: \ @com.liferay.portal.dao.orm.custom.sql-1.0.22.jar

from service.xml--------------------------dependency-injector use with spring. Earlier with ds. <service-builder dependency-injector="spring"  package-path="com.liferay.docs.guestbook" mvcc-enabled="true">