2016-11-03 40 views
0

我正在編寫一個簡單的Sling過濾器以在AEM 5.6.1上運行。我已經使過濾器使用配置屬性,並且我希望它會顯示在/ system/console/configMgr中,但它不會。將SlingFilter添加到Apache Felix configMgr

@SlingFilter(generateComponent = true, generateService = true, order = -700, scope = SlingFilterScope.REQUEST) 
public class SimpleFilter implements Filter { 

    @Property(value = "property.defaultvalue") 
    private static final String PROPERTY_KEY = "property.key"; 

    private String configuredValue; 

    @Activate 
    protected void activate(final ComponentContext componentContext) throws Exception { 
     Map<String, String> config = (Map<String, String>) componentContext.getProperties(); 
     this.configuredValue = config.get(PROPERTY_KEY); 
    } 

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 
     System.out.println(this.configuredValue); 
    } 
} 

我能夠安裝包,看到過濾器是否工作,可以在/系統/控制檯/包找到它,但它不會加入到/系統/控制檯/的ConfigMgr像我認爲它會來自@Property註釋的含義。我錯過了一步嗎?

回答

1

如果需要將配置顯示在配置管理器中,則需要指定metatype = true以及generateComponent。默認情況下,metatype爲false。

@SlingFilter(generateComponent = true, 
    generateService = true, 
    metatype = true, 
    order = -700, 
    scope = SlingFilterScope.REQUEST) 

請參閱Apache Felix - SCR AnnotationsApache Felix Metatype Service以更好地理解它。