gpt4 book ai didi

spring - AEM 6.3 - 将 Felix 迁移到 OSGi 注释 : How to deal with propertyPrivate?

转载 作者:行者123 更新时间:2023-12-02 06:44:57 25 4
gpt4 key购买 nike

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

一旦我弄清楚了它是如何工作的,就非常简单了。但有一种情况我不知道如何处理:带有 propertyPriavte = 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,但它也可以在配置管理器中使用,并且可以在其中更改它的值。但我不想这样。

我怎样才能做到这一点?这可以通过 OSGi 注释实现吗?

谢谢您并致以最诚挚的问候!

最佳答案

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

@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

关于spring - AEM 6.3 - 将 Felix 迁移到 OSGi 注释 : How to deal with propertyPrivate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45509554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com