2016-11-03 89 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以更好地理解它。