<?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>How I can inject dependency of classes in an extension module?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=119785489" />
  <subtitle>How I can inject dependency of classes in an extension module?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=119785489</id>
  <updated>2026-04-05T19:09:45Z</updated>
  <dc:date>2026-04-05T19:09:45Z</dc:date>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119897620" />
    <author>
      <name>Mark Molina</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119897620</id>
    <updated>2020-09-03T17:25:52Z</updated>
    <published>2020-09-03T17:25:52Z</published>
    <summary type="html">Hello Upender, unfortunetly nop. If you can fix it please share, please!</summary>
    <dc:creator>Mark Molina</dc:creator>
    <dc:date>2020-09-03T17:25:52Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119856036" />
    <author>
      <name>Upender Kashyap</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119856036</id>
    <updated>2020-08-28T02:59:19Z</updated>
    <published>2020-08-28T02:59:19Z</published>
    <summary type="html">Hello Mark, I am facing the same issue.. did u get any solution for this?</summary>
    <dc:creator>Upender Kashyap</dc:creator>
    <dc:date>2020-08-28T02:59:19Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119813669" />
    <author>
      <name>Mark Molina</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119813669</id>
    <updated>2020-08-21T15:01:20Z</updated>
    <published>2020-08-21T15:01:20Z</published>
    <summary type="html">Hello David, actually I did, also I had clean all temporary files, etc but same results. Dependency injections are ok in other modules but still failling in EXT. I  can´t fin the reason...</summary>
    <dc:creator>Mark Molina</dc:creator>
    <dc:date>2020-08-21T15:01:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119799462" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119799462</id>
    <updated>2020-08-19T13:22:38Z</updated>
    <published>2020-08-19T13:22:38Z</published>
    <summary type="html">This looks right to me. Have you tried purging osgi/state?</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2020-08-19T13:22:38Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119788780" />
    <author>
      <name>Mark Molina</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119788780</id>
    <updated>2020-08-18T17:27:54Z</updated>
    <published>2020-08-18T17:27:54Z</published>
    <summary type="html">Additionally, if I test a similar code inside another Portlet Module it works fine. I don&amp;#39;t know if it could be related to the fact that extension modules are hooks for existing ones and when they are deployed some initializations or dependency injections don&amp;#39;t happens. </summary>
    <dc:creator>Mark Molina</dc:creator>
    <dc:date>2020-08-18T17:27:54Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119788409" />
    <author>
      <name>Mark Molina</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119788409</id>
    <updated>2020-08-18T16:49:03Z</updated>
    <published>2020-08-18T16:49:03Z</published>
    <summary type="html">Hello David, in fact when the new extension files are cloned into my Extension modues I think they are created as a copy of the original ones and includes the @Component annotation.&lt;br /&gt;This is my code for example,&lt;br /&gt;&lt;br /&gt;package com.liferay.login.web.internal.portlet;&lt;br /&gt;&lt;br /&gt;import com.liferay.login.web.IDP;&lt;br /&gt;import com.liferay.login.web.constants.LoginPortletKeys;&lt;br /&gt;import com.liferay.portal.kernel.model.Release;&lt;br /&gt;import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;&lt;br /&gt;import com.liferay.portal.kernel.theme.ThemeDisplay;&lt;br /&gt;import com.liferay.portal.kernel.util.WebKeys;&lt;br /&gt;import com.liferay.portal.security.sso.openid.connect.OpenIdConnect;&lt;br /&gt;import com.liferay.portal.security.sso.openid.connect.OpenIdConnectProviderRegistry;&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Collection;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import javax.portlet.Portlet;&lt;br /&gt;import javax.portlet.PortletException;&lt;br /&gt;import javax.portlet.RenderRequest;&lt;br /&gt;import javax.portlet.RenderResponse;&lt;br /&gt;&lt;br /&gt;import org.osgi.service.component.annotations.Component;&lt;br /&gt;import org.osgi.service.component.annotations.Reference;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author Peter Fellwock&lt;br /&gt; */&lt;br /&gt;@Component(&lt;br /&gt;	immediate = true,&lt;br /&gt;	property = {&lt;br /&gt;		&amp;#34;com.liferay.portlet.add-default-resource=true&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.css-class-wrapper=portlet-login&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.display-category=category.tools&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.icon=/icons/login.png&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.preferences-owned-by-group=true&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.private-request-attributes=false&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.private-session-attributes=false&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.render-weight=50&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.single-page-application=false&amp;#34;,&lt;br /&gt;		&amp;#34;com.liferay.portlet.use-default-template=true&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.display-name=Sign In&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.expiration-cache=0&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.init-param.add-process-action-success-action=false&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.init-param.config-template=/configuration.jsp&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.init-param.template-path=/META-INF/resources/&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.init-param.view-template=/login.jsp&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.name=&amp;#34; + LoginPortletKeys.LOGIN,&lt;br /&gt;		&amp;#34;javax.portlet.portlet-mode=text/html;config&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.resource-bundle=content.Language&amp;#34;,&lt;br /&gt;		&amp;#34;javax.portlet.security-role-ref=guest,power-user,user&amp;#34;&lt;br /&gt;	},&lt;br /&gt;	service = Portlet.class&lt;br /&gt;)&lt;br /&gt;public class LoginPortlet extends MVCPortlet {&lt;br /&gt;&lt;br /&gt;	@Reference(&lt;br /&gt;		target = &amp;#34;(&amp;amp;(release.bundle.symbolic.name=com.liferay.login.web)(&amp;amp;(release.schema.version&amp;gt;=1.0.0)(!(release.schema.version&amp;gt;=2.0.0))))&amp;#34;,&lt;br /&gt;		unbind = &amp;#34;-&amp;#34;&lt;br /&gt;	)&lt;br /&gt;	protected void setRelease(Release release) {&lt;br /&gt;	}&lt;br /&gt;	@Override&lt;br /&gt;	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)&lt;br /&gt;			throws IOException, PortletException {&lt;br /&gt;		List&amp;lt;IDP&amp;gt; providers = new ArrayList&amp;lt;IDP&amp;gt;();&lt;br /&gt;		ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);&lt;br /&gt;		long companyId = themeDisplay.getCompanyId();&lt;br /&gt;&lt;br /&gt;		if (_openIdConnect.isEnabled(companyId)) {&lt;br /&gt;			Collection&amp;lt;String&amp;gt; idps = _openIdConnectProviderRegistry.getOpenIdConnectProviderNames(companyId);&lt;br /&gt;			Iterator&amp;lt;String&amp;gt; iterator = idps.iterator();&lt;br /&gt;			while (iterator.hasNext()) {&lt;br /&gt;				providers.add(new IDP(iterator.next()));&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		renderRequest.setAttribute(&amp;#34;idps&amp;#34;, providers);&lt;br /&gt;&lt;br /&gt;		super.doView(renderRequest, renderResponse);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	@Reference&lt;br /&gt;	private OpenIdConnect _openIdConnect;&lt;br /&gt;&lt;br /&gt;	@Reference&lt;br /&gt;	private OpenIdConnectProviderRegistry&amp;lt;?, ?&amp;gt; _openIdConnectProviderRegistry;&lt;br /&gt;	&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Maybe I am missing something?&lt;br /&gt;&lt;br /&gt;Thanks for your help.</summary>
    <dc:creator>Mark Molina</dc:creator>
    <dc:date>2020-08-18T16:49:03Z</dc:date>
  </entry>
  <entry>
    <title>RE: How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119785841" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119785841</id>
    <updated>2020-08-17T23:42:05Z</updated>
    <published>2020-08-17T23:42:05Z</published>
    <summary type="html">It&amp;#39;s missing, but is your LoginPortlet also having an @Component annotation?  @Reference only works for @Components.&lt;br /&gt;&lt;br /&gt;I&amp;#39;m thinking it&amp;#39;s not. An @Component will not start unless all @Reference values are resolvable and wired in. If they were available and you had an @Component, then they would not be null. If they were not available and you had an @Component, then your component would not start. Regardless if they were available or not, if you are not an @Component you class can be instantiated and called and nothing gets &amp;#34;autowired&amp;#34; so the values would be null.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2020-08-17T23:42:05Z</dc:date>
  </entry>
  <entry>
    <title>How I can inject dependency of classes in an extension module?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119785488" />
    <author>
      <name>Mark Molina</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119785488</id>
    <updated>2020-08-17T21:58:28Z</updated>
    <published>2020-08-17T21:58:28Z</published>
    <summary type="html">Hello, I am developing a new extension for the Login module. I was able to modify the login.jsp page and change some texts (a simple POC) and these changes replaced correctly the original Login page.  Problem started when I tried to include more complexity...I want to add to my Login page, all the OpenId providers configured in the portal. As it is are existing modules, I added all the dependencies of the build.gradle file:dependencies {&lt;br /&gt;    ...&lt;br /&gt;    compileOnly &amp;#39;com.liferay:com.liferay.portal.security.sso.openid.connect.api&amp;#39;&lt;br /&gt;    compileOnly &amp;#39;com.liferay:com.liferay.portal.security.sso.openid.connect.impl&amp;#39;&lt;br /&gt;   ...    &lt;br /&gt;    originalModule group: &amp;#34;com.liferay&amp;#34;, name: &amp;#34;com.liferay.login.web&amp;#34;&lt;br /&gt;}&lt;br /&gt;After that were included all required jars to my project so there is no depency or compilation problem. Then I was able to include some classes in my new extended LoginPortlet.java.&lt;br /&gt;As documentation explain, I am including the variables with @Reference annotation:&lt;br /&gt;    @Reference&lt;br /&gt;    private OpenIdConnect _openIdConnect;    @Reference&lt;br /&gt;    private OpenIdConnectProviderRegistry&amp;lt;?, ?&amp;gt; _openIdConnectProviderRegistry;I am assuming that code fire Dependency Injection, so it is no needed to instatntiate manually. I am using them as follows:public class LoginPortlet extends MVCPortlet {    @Reference(&lt;br /&gt;        target = &amp;#34;(&amp;amp;(release.bundle.symbolic.name=com.liferay.login.web)(&amp;amp;(release.schema.version&amp;gt;=1.0.0)(!(release.schema.version&amp;gt;=2.0.0))))&amp;#34;,&lt;br /&gt;        unbind = &amp;#34;-&amp;#34;&lt;br /&gt;    )&lt;br /&gt;    protected void setRelease(Release release) {&lt;br /&gt;    }&lt;br /&gt;    @Override&lt;br /&gt;    public void doView(RenderRequest renderRequest, RenderResponse renderResponse)&lt;br /&gt;            throws IOException, PortletException {&lt;br /&gt;        List&amp;lt;IDP&amp;gt; providers = new ArrayList&amp;lt;IDP&amp;gt;();&lt;br /&gt;        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);&lt;br /&gt;        long companyId = themeDisplay.getCompanyId();        if (_openIdConnect.isEnabled(companyId)) {&lt;br /&gt;            Collection&amp;lt;String&amp;gt; idps = _openIdConnectProviderRegistry.getOpenIdConnectProviderNames(companyId);&lt;br /&gt;            Iterator&amp;lt;String&amp;gt; iterator = idps.iterator();&lt;br /&gt;            while (iterator.hasNext()) {&lt;br /&gt;                providers.add(new IDP(iterator.next()));&lt;br /&gt;            }&lt;br /&gt;        }        renderRequest.setAttribute(&amp;#34;idps&amp;#34;, providers);        super.doView(renderRequest, renderResponse);&lt;br /&gt;    }    @Reference&lt;br /&gt;    private OpenIdConnect _openIdConnect;    @Reference&lt;br /&gt;    private OpenIdConnectProviderRegistry&amp;lt;?, ?&amp;gt; _openIdConnectProviderRegistry;&lt;br /&gt;    &lt;br /&gt;}My problem is that at execution time it throws a NPE and I don&amp;#39;t know the reason. In fact if I debugg the code,  referenced variables _openIdConnect and  _openIdConnectProviderRegistry were not autowired.Finally same happens if I try to use any class of the OpenId module in the login.jsp directly.There is anyone can help me please?Regards,Mark&lt;br /&gt;  </summary>
    <dc:creator>Mark Molina</dc:creator>
    <dc:date>2020-08-17T21:58:28Z</dc:date>
  </entry>
</feed>
