【发布时间】:2018-09-08 08:16:16
【问题描述】:
我正在尝试在我的项目中使用 getSlingScriptHelper().getService,但它一直返回 null。我在其他项目中也这样做过,实现方式类似。我们在项目中使用了 AEM 6.3。我的代码如下:
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 实施:
@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;
}
}
日志显示“FOOInterface value is : null”。
我尝试过使用类注入方法的 sling 模型,但它也不起作用。
【问题讨论】: