Activate method not getting executed

Avatar

Avatar

manpreetk

Avatar

manpreetk

manpreetk

12-06-2019

Hi All, I have created a simple service in Sling and deployed the same on my AEM instance. However, the activate method is not getting called for this class. Here is my implementation class: package com.company.project.auth.impl; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.metatype.annotations.Designate; import org.slf4j.Logger; @Designate(ocd=MyConfiguration.class) @Component(service = MyRequestImpl.class, immediate = true, configurationPid = "com.company.project.auth.impl.MyRequestImpl") public class MyRequestImpl implements MyRequest{                 protected final transient Logger logger = LoggerFactory.getLogger(this.getClass());                                 @Activate                 protected void activate(                                                 final MyConfiguration config) {                                 logger.info("Calling Activate");                 }                 @Override                 public String myFunction() {                                 logger.info("Calling my function");                          } } I am able to see  the log, "Calling my function" but not the one, "Calling Activate". Please suggest a solution.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

13-06-2019

Hi,

Can you check if your service is active or not? I tried with your code with small modification works for me.

package com.aem.community.core.services;

import org.osgi.service.component.annotations.Activate;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.metatype.annotations.Designate;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import com.aem.community.core.Config;

@Designate(ocd = Config.class)

@Component(service = MyRequest.class, immediate = true, configurationPid = "com.aem.community.core.services.MyRequest")

public class MyRequestImpl implements MyRequest {

  protected final transient Logger logger = LoggerFactory.getLogger(this.getClass());

  @Activate

  protected void activate(final Config config) {

  logger.info("Calling Activate");

  }

  @Override

  public String myFunction() {

  logger.info("Calling my function");

  return "myfunction";

  }

}

Answers (3)

Answers (3)

Avatar

Avatar

akshat_jain09

Avatar

akshat_jain09

akshat_jain09

18-06-2019

Well I am not getting any exception, and the code is also same. Its just that I am using my custom service and configuration so the pid also differs.

But not getting the desired result.

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

18-06-2019

Are you getting any exception? Can you try with my code.

I used my config and changed Pid and service in @component annotation.

Avatar

Avatar

akshat_jain09

Avatar

akshat_jain09

akshat_jain09

18-06-2019

Hi Arun

I checked that the service is active. But still On hitting the service, I am not able to see the activate log.

Can you suggest what change made it work for you?