1
votes

I am trying to use the getSlingScriptHelper().getService in my project but it keeps returning null. I have done this in other projects and the implementation is similar. We are using sightly on AEM 6.3 in the project. My code below:

FOOModel :

  public class FOOModel extends WCMUsePojo {

private static final Logger LOGGER = LoggerFactory.getLogger(FOOModel.class);

        private String foo;


        @Override
        public void activate() throws Exception{

            FOOInterface fooInterface = getSlingScriptHelper().getService(FOOInterface.class);   

        LOGGER.info("FOOInterface value is : " + fooInterface);

        }

        public String getFoo() {        
            return foo;
        }

    }

FooInterface :

public interface FOOInterface {

    public String getFoo();

}

FOO Implementation :

@Component(metatype = true, immediate = true, label = "FOO Configuration", description = "OSGi Configuration FOO")
@Service(FOOInterface.class)
public class FOOImpl implements FOOInterface {


    @Property(label = "FOO", description = "FOO to be provided")
    public static final String FOO_URL = "foo.url";


    private String foo;



    @Activate
    public void activate(ComponentContext componentContext){
        Dictionary<?, ?> props = componentContext.getProperties();
        this.foo = PropertiesUtil.toString(props.get(FOO_URL), StringUtils.EMPTY);

    }

    @Override
    public String getSsoUrl() {
        return foo;
    }


}

The logs show "FOOInterface value is : null".

I've tried the sling model with class injection method but it did not work either.

EDIT : I have found that the service is not active. Attaching screenshot for the bundle status. Bundle status

1

1 Answers

1
votes

Most probably your FOOInterface service is not active. You can check /system/console/components to see its status.

The bundle that includes that service might not be properly installed. You can check its status at /system/console/bundles.