java - ResourceInfo not injected into spring managed jersey filter -
i having problems injecting resourceinfo jersey filter. annotation @context doesn't seem work when having spring managed filter instance.
what found this: jersey request filter on uri
the second goal quite similar situation.
dynamicfeature:
@provider public class httpcacheconfigdynamicfeature implements dynamicfeature { private final defaulthttpcachefilter defaulthttpcachefilter; private final httpcachefilter httpcachefilter; @autowired public httpcacheconfigdynamicfeature(defaulthttpcachefilter defaulthttpcachefilter, httpcachefilter httpcachefilter) { this.defaulthttpcachefilter = defaulthttpcachefilter; this.httpcachefilter = httpcachefilter; } ...
filter:
@component public class httpcachefilter implements containerresponsefilter { private log logger = logfactory.getlog(httpcachefilter.class); private final configurationcontroller configurationcontroller; @context private resourceinfo resourceinfo; @autowired public httpcachefilter(configurationcontroller configurationcontroller) { this.configurationcontroller = configurationcontroller; } ...
the resource info null.
what change dynamicfeature little that:
@provider public class httpcacheconfigdynamicfeature implements dynamicfeature { private final defaulthttpcachefilter defaulthttpcachefilter; private final configurationcontroller configurationcontroller; @autowired public httpcacheconfigdynamicfeature(defaulthttpcachefilter defaulthttpcachefilter, configurationcontroller configurationcontroller) { this.defaulthttpcachefilter = defaulthttpcachefilter; this.configurationcontroller = configurationcontroller; } @override public void configure(resourceinfo resourceinfo, featurecontext featurecontext) { if (hashttpcacheconfigannotation(resourceinfo)) { featurecontext.register(new httpcachefilter(configurationcontroller, resourceinfo), 50); } else { featurecontext.register(defaulthttpcachefilter, 51); } }
maybe know more elegant way achieve goals.
thanks!
christoph
in normal cases work, jersey still inject it. there known issue dynamicfeature , registering instances. if register class (i.e. register(httpcachefilter.class)
), injections work.
in case, don't see reason need manually pass configurationcontroller
httpcachefilter
instantiate. if register class in previous example, automatically injected.
also (not tested) think can clean , use @inject
on constructor of filter. can have both resourceinfo
, configurationcontroller
both constructor arguments. not big deal, me it's looks cleaner having 1 injection point. said, didn't test it, i'm pretty sure work. @inject
, @context
pretty interchangeable jersey, , can use @inject
spring components in jersey, imagine works.
Comments
Post a Comment