AEM 6.3 - 将 Felix 迁移到 OSGi 注释:如何处理 propertyPrivate?

AEM 6.3 - Migrate Felix to OSGi annotations: How to deal with propertyPrivate?

我正在将 AEM 6.1 应用程序迁移到 AEM 6.3。由于 Felix 注释 (org.apache.felix.scr.annotations.*) 已被弃用,我决定将我的组件迁移到 OSGi 注释 (org.osgi.service.component.annotations.*).

一旦弄清楚它是如何工作的,就很容易了。但是有一种情况我不知道如何处理: 属性Priavte = true.

的属性

旧的实现是这样的:

@Component(metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = "sling.servlet.selectors", value = "overlay", propertyPrivate = true),
})
public class OverlayServletImpl extends OverlayServlet {
...
}

属性sling.servlet.selectors 无法在 AEM 控制台的配置管理器中配置,但由于配置文件,它可以配置,正确的?所以,我还需要定义这个属性.

对于其他属性,我改变了我的实现方式:

// OverlayServletImpl
@Component(
        service = Servlet.class,
        configurationPid = "my.package.path.OverlayServletImpl"
)
@Designate(
        ocd = OverlayServletImplConfiguration.class
)
public class OverlayServletImpl extends OverlayServlet {
...
}

// Configuration
@ObjectClassDefinition(name = "Overlay Servlet")
public @interface OverlayServletImplConfiguration {

    String sling_servlet_selectors() default "overlay";
...
}

现在,我有 属性 sling.servlet.selectors,但它在 Configuration Manager 中也可用,并且可以在那里更改它的值。但我不想那样。

我该怎么做?这可以通过 OSGi 注释实现吗?

谢谢你,并致以最诚挚的问候!

据我所知这是不可能的。您定义的每个 属性 都可以被配置覆盖。

如果您使用 @Component 注释来指定您的私有属性,这似乎是可能的。

@Component(service = Servlet.class,
  property = 
  { SLING_SERVLET_RESOURCE_TYPES + "=aemhtlexamples/structure/page",
    SLING_SERVLET_METHODS + "=GET", 
    SLING_SERVLET_EXTENSIONS + "=html", 
    SLING_SERVLET_SELECTORS + "=hello" })
public class SimpleServlet extends SlingSafeMethodsServlet {

  @Override
  protected void doGet(final SlingHttpServletRequest req, final SlingHttpServletResponse resp)
        throws ServletException, IOException {
    final Resource resource = req.getResource();
    resp.getOutputStream().println(resource.toString());
    resp.getOutputStream().println("This content is generated by the SimpleServlet");
  }
}

来源:https://github.com/heervisscher/htl-examples/blob/master/core/src/main/java/com/adobe/examples/htl/core/servlets/SimpleServlet.java