0

I have simple Apache Meecrowave 1.2.1 (OWB+CXF) application with ContainerRequestFilter:

@Singleton
@Provider
public class AppInstanceAndSecurityFilter implements ContainerRequestFilter {
    ...
    @Inject
    private AppInstanceService appInstanceService;
    ...
    @Context
    private ResourceInfo resourceInfo;
    ...
}

AppInstanceAndSecurityFilter class is returned in getClasses() method of Application subclass.

The problem is that filter is called twice and there are two instances of filter - one with all successfully resolved @Inject and @Context references and one with all @Inject references null and all @Context references successfully resolved.

Why there are two instances of filter, one with null @Inject references?

Pavel Arnošt
  • 97
  • 2
  • 8
  • The one with null @Inject reference is managed by the jaxrs runtime provider, while the one is managed by CDI. I think this is because you have used `@Singleton` which is from `javax.inject.Singleton` – maress Jul 11 '18 at 17:56
  • @maress I removed Singleton annotation, but it didn't change anything. Still two instances, one with null Inject references. Strange. I defined filter in getSingletons() instead of getClasses() and resolved filter instance manually and it works as it should (only one instance will fully resolved Inject and Context references), but I don't see reason why getClasses() shouldn't work. – Pavel Arnošt Jul 12 '18 at 06:18
  • It is because the getClasses() instances are instantiated by CXF and not CDI. The best is likely to configure the scanning to exclude the providers/endpoints your don't want and not implement getClasses. See https://issues.apache.org/jira/browse/CXF-7789 – Romain Manni-Bucau Jul 15 '18 at 09:51
  • @RomainManni-Bucau Thanks for reporting this. But if getClasses() instances are only instantiated by CXF and there are two instances of ContainerRequestFilter, something must be instantiating that other instance - maybe CXF CDI integration? And ApplicationScoped resource classes defined in getClasses() work without problems (they are called only once and all references are resolved successfully). But maybe that's a happy accident :-) – Pavel Arnošt Jul 15 '18 at 20:40
  • How do you bootstrap your app – Lev Kuznetsov Jul 16 '18 at 15:27

0 Answers0