Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring AEM 6.3-将Felix迁移到OSGi注释:如何处理propertyPrivate?_Spring_Annotations_Osgi_Aem_Apache Felix - Fatal编程技术网

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

Spring AEM 6.3-将Felix迁移到OSGi注释:如何处理propertyPrivate?,spring,annotations,osgi,aem,apache-felix,Spring,Annotations,Osgi,Aem,Apache Felix,我正在将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

我正在将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 {
...
}
// 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在AEM控制台的Configuration Manager中是不可配置的,但由于配置文件的缘故,它是可配置的,对吗?所以,我仍然需要定义这个属性

对于其他属性,我更改了实现,如下所示:

@Component(metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = "sling.servlet.selectors", value = "overlay", propertyPrivate = true),
})
public class OverlayServletImpl extends OverlayServlet {
...
}
// 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");
  }
}

来源:

您好,很抱歉我的ate回复,但我无法处理该主题并检查是否有效@mickleroy的答案是正确的,并且有效。您有任何与OSGI注释迁移相关的文档吗?我也在从AEM6.1迁移到6.3。。有必要迁移它们吗?您好!Felix注释已被弃用,但它们仍适用于AEM 6.3。这意味着现在还没有必要迁移它们,但在AEM的未来版本中将会这样做。作为文档,我推荐下一页。还有一个指向GitHub项目的链接,它显示了如何使用Felix注释和官方OSGi注释实现一个或多个相同的服务。这对我的迁移帮助很大。