将 SlingFilter 添加到 Apache Felix configMgr
Adding a SlingFilter to Apache Felix configMgr
我正在为 AEM 5.6.1 上的 运行 编写一个简单的 Sling 过滤器。我已经让过滤器使用配置属性,我希望它会出现在 /system/console/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);
}
}
我可以安装捆绑包,看到过滤器正在工作并且可以在 /system/console/bundles 中找到它,但它并没有像我想的那样被添加到 /system/console/configMgr @属性 注释的存在。我错过了一步吗?
如果需要配置显示在配置管理器中,则需要指定 metatype = true
和 generateComponent
。默认元类型为 false。
@SlingFilter(generateComponent = true,
generateService = true,
metatype = true,
order = -700,
scope = SlingFilterScope.REQUEST)
参考 Apache Felix - SCR Annotations and Apache Felix Metatype Service 以更好地理解它。
我正在为 AEM 5.6.1 上的 运行 编写一个简单的 Sling 过滤器。我已经让过滤器使用配置属性,我希望它会出现在 /system/console/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);
}
}
我可以安装捆绑包,看到过滤器正在工作并且可以在 /system/console/bundles 中找到它,但它并没有像我想的那样被添加到 /system/console/configMgr @属性 注释的存在。我错过了一步吗?
如果需要配置显示在配置管理器中,则需要指定 metatype = true
和 generateComponent
。默认元类型为 false。
@SlingFilter(generateComponent = true,
generateService = true,
metatype = true,
order = -700,
scope = SlingFilterScope.REQUEST)
参考 Apache Felix - SCR Annotations and Apache Felix Metatype Service 以更好地理解它。