【问题标题】:Adding a SlingFilter to Apache Felix configMgr将 SlingFilter 添加到 Apache Felix configMgr
【发布时间】:2017-03-17 15:45:57
【问题描述】:

我正在编写一个简单的 Sling 过滤器以在 AEM 5.6.1 上运行。我已经让过滤器使用配置属性,我希望它会出现在 /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 @Property 注释的存在。我错过了一步吗?

【问题讨论】:

    标签: osgi aem sling


    【解决方案1】:

    如果您需要配置出现在配置管理器中,您需要指定metatype = truegenerateComponent。默认情况下,元类型为 false。

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

    请参阅 Apache Felix - SCR AnnotationsApache Felix Metatype Service 以更好地理解它。

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2018-05-14
      相关资源
      最近更新 更多