2017-08-04 107 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

據我所知這是不可能的。您定義的每個屬性都可以通過配置覆蓋。