<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Null service @Reference...but the component's reference says SATISFIED</title>
  <link rel="self" href="https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=118979813" />
  <subtitle>Null service @Reference...but the component's reference says SATISFIED</subtitle>
  <id>https://uat.liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=118979813</id>
  <updated>2026-10-15T12:00:20Z</updated>
  <dc:date>2026-10-15T12:00:20Z</dc:date>
  <entry>
    <title>RE: Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119246003" />
    <author>
      <name>Enrique Valdes Lacasa</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119246003</id>
    <updated>2020-05-26T21:21:55Z</updated>
    <published>2020-05-26T21:21:55Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;I made a finding in respect to model implementations. So besides sharing it, I'm going to give more background on what I meant with my last message.&lt;br&gt;&lt;br&gt;So in my Member document contributor (which is an OSGi component):&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(
        immediate = true,
        property = "indexer.class.name=xxx.Member",
        service = ModelDocumentContributor.class
)
public class MemberModelDocumentContributor implements ModelDocumentContributor&amp;lt;member&amp;gt; {

    @Override
    public void contribute(Document document, Member member) {

        document.addNumber(Field.COMPANY_ID, member.getCompanyId());
        document.addNumber(Field.GROUP_ID, member.getGroupId());
        document.addNumber(Field.SCOPE_GROUP_ID, member.getGroupId());
        ...
        // more field additions to search document
        ...
    }
    
}&amp;lt;/member&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;If I add some logic using OSGi references in my MemberImpl class:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(
    immediate = true,
    service = Member.class
)
public class MemberImpl extends MemberBaseImpl {
    /*
    * NOTE FOR DEVELOPERS:
    *
    * Never reference this class directly. All methods that expect a member public profile model instance should use the {@link org.cbdce.portal.member.model.MemberPublicProfile} interface instead.
    */
	public MemberImpl() {
	}
	
	[my custom model methods]
	
	@Reference
	private UserLocalService _uls;
	
	}
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;...the Member object that gets passed within the contribute method (the "member" parameter)...is not an OSGi object, and so _uls is going to be null.&lt;br&gt;&lt;br&gt;I realized a possible workaround...although it feels wrong to me...but maybe it's the way to go. Again, any feedback = greatly appreciated!&lt;br&gt;&lt;br&gt;If I create my own reference of a Member in my document contributor...like this:&lt;br&gt;&lt;br&gt;    &lt;pre&gt;&lt;code&gt;@Reference
    private Member _member;
    &lt;/code&gt;&lt;/pre&gt;    &lt;br&gt;and then, I noticed there is a method within model entities called getModelAttributes() (inherited from BaseModel class)...and at the same time, a setModelAttributes(). So using these methods I can do this:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(
        immediate = true,
        property = "indexer.class.name=xxx.Member",
        service = ModelDocumentContributor.class
)
public class MemberModelDocumentContributor implements ModelDocumentContributor&amp;lt;member&amp;gt; {

    @Override
    public void contribute(Document document, Member member) {

        _member.setModelAttributes(member.getModelAttributes());

        document.addNumber(Field.COMPANY_ID, _member.getCompanyId());
        document.addNumber(Field.GROUP_ID, _member.getGroupId());
        document.addNumber(Field.SCOPE_GROUP_ID, _member.getGroupId());
        ...
        // more field additions to search document
        ...
    }
    
    @Reference
    private Member _member;

}
&amp;lt;/member&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Now my _member reference has the reference&amp;nbsp; (userLocalService)&amp;nbsp;injected correctly AND all the required "member" model attributes (id, the companyId, groupId, etc...everything).&lt;br&gt;&lt;br&gt;Does this seem like a good way to go? I'm concerned that Member instances wouldn't be initialized as OSGi references somewhere else and would get NullPointerException...although it could be a suitable workaround for my situation.&lt;br&gt;&lt;br&gt;Thanks!!!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Enrique Valdes Lacasa</dc:creator>
    <dc:date>2020-05-26T21:21:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119245585" />
    <author>
      <name>Enrique Valdes Lacasa</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119245585</id>
    <updated>2020-05-26T18:53:55Z</updated>
    <published>2020-05-26T18:53:55Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hello again everyone!&lt;br&gt;&lt;br&gt;I watched the course, Christoph; it was informative, thanks!&lt;br&gt;&lt;br&gt;I got to a new question related to this...hopefully someone can shed some light.&lt;br&gt;&lt;br&gt;This time is about using OSGi references within [ENTITY_NAME]Impl classes (the model implementation classes generated in Service Builder; S&lt;img alt="emoticon" src="@theme_images_path@/emoticons/cool.gif"&gt;. Let's say I have a SB entity called Member and want to have some logic in my MemberImpl class to use some services. For example:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Reference
private UserLocalService _uls;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;In a Member document contributor wehre I index some search fields...I notice that member instances have  _uls as null (in the same way as it was null whenever I manually instantiated the search container from my original question). I gave a look to how Liferay deals with this within its [ENTITY_NAME]Impl classes in its source code...but for example in UserImpl, they use all xxxLocalServiceUtils around (which are supposed to be non-preferred when working in OSGi).&lt;br&gt;&lt;br&gt;So is there a recommended approach to use OSGI in [ENTITY_NAME]Impl classes? Is OSGi appropriate to use in SB [ENTITY_NAME]Impl classes at all?  I browsed through the documentation but couldn't get any ideas out of it.&lt;br&gt;&lt;br&gt;Thanks in advance!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Enrique Valdes Lacasa</dc:creator>
    <dc:date>2020-05-26T18:53:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119129590" />
    <author>
      <name>Enrique Valdes Lacasa</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119129590</id>
    <updated>2020-05-09T17:29:18Z</updated>
    <published>2020-05-09T17:29:18Z</published>
    <summary type="html">Thanks a lot for the feedback Cristoph! &lt;br /&gt;It makes more sense after reading your message.  And I&amp;#39;ll check out the course!</summary>
    <dc:creator>Enrique Valdes Lacasa</dc:creator>
    <dc:date>2020-05-09T17:29:18Z</dc:date>
  </entry>
  <entry>
    <title>RE: Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119120115" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119120115</id>
    <updated>2020-05-08T07:46:53Z</updated>
    <published>2020-05-08T07:46:53Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;The runtime can't really call non-empty constructors. It would have to detect all constructors, determine the parameters and somehow find a way to add them. While this is certainly possible, it makes the process highly complicated.&lt;br&gt;Also, all constructors with unknown parameters must be discarded. This would make the system quite error prone because you would never really know, which constructor is called.&lt;br&gt;Basically: You should not instantiate components directly, you should always reference them. If it was more convenient (for whatever reasons) to you to instantiate the class yourself (e.g. in a factory)&lt;br&gt;&lt;pre&gt;&lt;code&gt;MemberSearchContainer msc = new MemberSearchContainer(...);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;then you have to call setMemberLocalService yourself.&lt;br&gt;&lt;br&gt;For better understanding of OSGI I can really recommend the osgi course by Olaf Kock:&lt;br&gt;&lt;a href="https://university.liferay.com/osgi-basics"&gt;https://university.liferay.com/osgi-basics&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2020-05-08T07:46:53Z</dc:date>
  </entry>
  <entry>
    <title>RE: Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119119450" />
    <author>
      <name>Enrique Valdes Lacasa</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119119450</id>
    <updated>2020-05-07T21:19:03Z</updated>
    <published>2020-05-07T21:19:03Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;All right, I'll answer myself! &lt;br&gt;&lt;br&gt;I went past the issue...but I feel I could still&amp;nbsp;have a better understanding about the problem. Since I am learning OSGi, I guess I wasn't paying close attention to the bedrocks.&lt;br&gt;&lt;br&gt;I forgot to mention the way I was instantiating MemberSearchContainer (since it was a long post already). The way I was doing it, was by using a plain old custom parameterized Java constructor, like:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;MemberSearchContainer msc = new MemberSearchContainer(...);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;BUT since OSGi takes care of the injection, my references in the POJO were null because (I think) I was the one instantiating the object...NOT OSGi. &lt;br&gt;&lt;br&gt;So instead of doing that, in the portlet class, I just did: &lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Reference
private MemberSearchContainer _msc;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;And once I did that, my _msc variable had all the references piped in via OSGi!&lt;br&gt;&lt;br&gt;The thing that seems confusing is that OSGi just makes use of an empty constructor...so you get your instance, but it won't have taken in any parameters. I wrote a getMemberSearchConstructor getter and make it return MemberSearchContainer.&lt;br&gt;&lt;br&gt;I'm glad I went past it! Any light on the subject and if there is a best practice to improve the instantiation will still be appreciated.&lt;br&gt;&lt;br&gt;Thanks!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Enrique Valdes Lacasa</dc:creator>
    <dc:date>2020-05-07T21:19:03Z</dc:date>
  </entry>
  <entry>
    <title>Null service @Reference...but the component's reference says SATISFIED</title>
    <link rel="alternate" href="https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118979812" />
    <author>
      <name>Enrique Valdes Lacasa</name>
    </author>
    <id>https://uat.liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118979812</id>
    <updated>2020-04-19T19:20:09Z</updated>
    <published>2020-04-19T19:20:09Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Good day Liferay Community. &lt;br&gt;&lt;br&gt;Any help will be greatly appreciated - thank you beforehand.&lt;br&gt;&lt;br&gt;I created a component consisting of a POJO class like this:&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(
        immediate = true,
        service = MemberSearchContainer.class
    )
    public class MemberSearchContainer {   
    
    public MemberSearchContainer () {   }
    
    [...]
    
        @Reference
        private MemberLocalService mls;
    }&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;All looks good when deploying the bundle - just the regular INFO messages.&lt;br&gt;&lt;br&gt;I connect to Apache GoGo , and look for the bundle's info:&lt;br&gt;&lt;pre&gt;&lt;code&gt;g! b 1081
Id=1081, Status=ACTIVE
"Registered Services"
[...]
{xxx.member.portlet.model.MemberSearchContainer}={service.id=13234, service.bundleid=1081, service.scope=bundle, component.name=xxx.portal.member.portlet.model.MemberSearchContainer, component.id=5716}
[...]&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;And after that I look for information about the component doing:&lt;br&gt;&lt;pre&gt;&lt;code&gt;g! scr:info 5716
    Component Description: xxx.portal.member.portlet.model.MemberSearchContainer
    ==================================================================================
    Class:        xxx.portal.member.portlet.model.MemberSearchContainer
    Bundle:        1081 (xxx.portal.member.admin:0.1.0.SNAPSHOT)
    Enabled:       true
    Immediate:     true
    Services:      [xxx.portal.member.portlet.model.MemberSearchContainer]
    Scope:         singleton
    Config PID(s): [xxx.portal.member.portlet.model.MemberSearchContainer], Policy: optional
    Base Props:    (0 entries)
    
    Component Configuration Id: 5716
    --------------------------------
    State:        ACTIVE
    Service:      13234 [xxx.portal.member.portlet.model.MemberSearchContainer]
    Config Props: (2 entries)
      component.id&amp;lt;long&amp;gt; = 5716
      component.name&amp;lt;string&amp;gt; = xxx.portal.member.portlet.model.MemberSearchContainer
    References:   (total 1)
      - mls: xxx.portal.member.service.MemberLocalService SATISFIED 1..1 static
        target=(*) scope=bundle (1 binding):
        * Bound to [13044] from bundle 1079 (xxx.portal.member.service:0.1.0.SNAPSHOT)
&amp;lt;/string&amp;gt;&amp;lt;/long&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;So in the "References" section we can see that indeed the MemberLocalService reference is actually SATISFIED.&lt;br&gt;&lt;br&gt;But...when I debug the component, I notice that the MemberLocalService mls variable is null...so it's not being injected, and I'm not sure why. I tried many things and can't understand what's going on.&lt;br&gt;&lt;br&gt;By the way - in a portlet component within the same bundle, when I use this:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Reference
    private MemberLocalService mls;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;The service gets injected without a problem.&lt;br&gt;&lt;br&gt;I'm very intrigued to understand what's happening. Any feedback will be of great help.&lt;br&gt;&lt;br&gt;Thanks a lot!&lt;br&gt;&lt;br&gt;Best regards,&lt;br&gt;Enrique&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Enrique Valdes Lacasa</dc:creator>
    <dc:date>2020-04-19T19:20:09Z</dc:date>
  </entry>
</feed>
