【问题标题】:How to migrate scr annotations of AdaptorFactory class to OSGI R6 annotations?如何将 AdaptorFactory 类的 scr 注解迁移到 OSGI R6 注解?
【发布时间】:2018-03-12 02:25:15
【问题描述】:

我们正在从 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"
})

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

【问题讨论】:

    标签: osgi aem


    【解决方案1】:

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

    例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-17
      • 2018-04-27
      • 2017-04-07
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      相关资源
      最近更新 更多