如何将AdaptorFactory类的scr注释迁移到OSGI R6注释?

时间:2018-03-12 02:25:16

标签: osgi aem

我们正在从AEM 6.0迁移到6.3,并且正在从Felix迁移到OSGI scr注释。 我有这样的代码

@Component
@Service(AdapterFactory.class)
@Properties({
        @Property(name = "CustomManagerAdapter", value = "adapter/factory"),
        @Property(name = SlingConstants.PROPERTY_ADAPTABLE_CLASSES, value = {
            "org.apache.sling.api.resource.ResourceResolver",
            "org.apache.sling.api.SlingHttpServletRequest",
            "org.apache.sling.api.resource.Resource"
        }),
        @Property(name = SlingConstants.PROPERTY_ADAPTER_CLASSES, value = "com.myapp.util.user.CustomUser")
})
public class CustomUserAdapter implements AdapterFactor

如何将SlingConstants.PROPERTY_ADAPTABLE_CLASSES等多值属性转换为R6注释?

我试过了:

@Component(service = AdapterFactory.class, property={
        SlingConstants.PROPERTY_ADAPTER_CLASSES + "=com.myapp.util.user.CustomUser",
        SlingConstants.PROPERTY_ADAPTABLE_CLASSES+"={\"org.apache.sling.api.resource.ResourceResolver\"}",
        "CustomManagerAdapter=adapter/factory"
})

这没有用。请分享一个迁移多值属性的示例。

1 个答案:

答案 0 :(得分:5)

要注册多值属性,请多次重复该属性的声明。当属性值改变时,键,即属性名称保持不变。

例如:

@Component(
service = AdapterFactory.class,
immediate = true,
property = {
    "adaptables=org.apache.sling.api.resource.Resource",
    "adaptables=org.apache.sling.api.SlingHttpServletRequest",
    "adapters=<Myclass>"
 }
)