Hi @jayv25585659,
When you use the Sling annotation:
@Component(service = Filter.class)
@SlingServletFilter(
scope = { SlingServletFilterScope.REQUEST },
pattern = "^/content/myapp/sg/en/(?:login|members).*"
)
@ServiceRanking(101)
public class MyFilter implements javax.servlet.Filter { ... }
BND must turn those property-type annotations into real OSGi service properties. If your project isn’t set up for that, the filter registers without sling.filter.scope / sling.filter.pattern, so Sling never calls it - hence “works with @Component properties, stops with @SlingServletFilter”.
Try this:
-
Add the annotation dependency (provided scope):
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.servlets.annotations</artifactId>
<version>1.x.x</version>
<scope>provided</scope>
</dependency>
-
Make sure BND processes OSGi R7 annotations + property types.
Using maven-bundle-plugin, ensure DS is enabled (modern archetypes already do):
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<-dsannotations>*</-dsannotations>
<-metatype>true</-metatype>
</instructions>
</configuration>
</plugin>
(If you use bnd-maven-plugin, ensure it’s recent - Bnd 5+ - so @ComponentPropertyType is handled.)
-
Verify at runtime:
-
/system/console/services - your class - you should see
sling.filter.scope = [REQUEST],
sling.filter.pattern = ^/content/myapp/sg/en/(?:login|members).*,
service.ranking = 101.
If these aren’t there, your build still isn’t generating properties.
If you don’t want to touch build config, the safe, supported route is exactly what you had working:
@Component(service = Filter.class, property = {
"sling.filter.scope=REQUEST",
"sling.filter.pattern=^/content/myapp/sg/en/(?:login|members).*",
"service.ranking:Integer=101"
})
public class MyFilter implements Filter { ... }
Either way works; the first is “Sling style” (needs build support), the second is plain OSGi (works out of the box in most AEM projects).