2017-08-04 40 views
2

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

一旦我想清楚它是如何工作的,它很容易。但有一种情况我不知道如何处理:属性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注释?

谢谢,最好的问候!

+0

你有相关的OSGI注释迁移任何文件?我也从AEM6.1迁移到6.3 ..是否有必要迁移它们? – Sara

+1

你好! Felix注释已弃用,但它们仍在AEM 6.3中工作。这意味着它没有必要迁移它们,但它将在未来的AEM版本中。 作为文件,我推荐以下页面[AEM官方OSGI宣言服务注释](http://www.nateyolles.com/blog/2017/05/osgi-declarative-services-annotations-in-aem)。还有一个GitHub项目的链接,该项目显示了如何使用Felix注释和官方OSGi注释来实现同样的服务。这对我的迁移帮助很大。 – user2960606

回答

0

看起来如果您使用@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

+0

你好,抱歉我的吃了回应,但我不能在这个主题上工作,并检查这是否有效。 @ mickleroy的回答是正确的,并有效。 – user2960606

0

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