Search code examples
osgimaven-scr-plugin

Maven SCR Plugin Reference Annotation Target Attribute Usage


You can filter out available implementations through the "target" attribute of the @Reference as shown below:

@Reference(target="(k1=v1)") ISomeServiceContract svc1;

My question is about the filter value. The documentation says very little about it and I am confused.

http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html#reference states the following for the "target" attribute:

"A service target filter to select specific services to be made available".

Do filter values in SCR plugin have a specific syntax (i.e. why do I even need the parenthesis surrounding key equals value specification)? Does it allow you to specify things like "(k1=v1&&k2=v2)" or "(k1=v1||k2=v2&&(...))".


Solution

  • The syntax is explained in chapter "3.2.7 Filter syntax" of OSGi Core specification. The filters you define in the SCR annotation are OSGi filters. Some examples:

    (k1=v1)
    (&(k2=v1)(k2=v2))
    (&(|(k1=v1)(k2=v2))(k3=v3))
    

    The syntax that OSGi specifies is the same as for LDAP search filters.