Saturday, 15 August 2015

How do I create a sub-resource with spring dependencies @autowired with apache cxf -



How do I create a sub-resource with spring dependencies @autowired with apache cxf -

i can't figure out how spring autowire dependencies in sub resource. need specify request state sub resource. i'll need access cxf managed @contexts.

if have class

@path("/resource/") public class resource { @autowired private dependency @path("{id}/sub/") public getsub(@pathparam("id") string id){ // know not right. autowire subresource, needs // request scoped , errors proxying request scoped bean // singleton bean. // have tried instantiating subresource using resourcecontext // subresource's dependencies don't injected homecoming new subresource(id); } }

and class

public class subresource{ @context private uriinfo uriinfo; @autowired private dependency2 dependency2; private string id; public subresource(string id){ } @get public response get(){ homecoming response.ok(id).build(); } }

how spring managed dependencies auto injected in sub resources? how sub resource access cxf managed dependencies?

i create mill bean instantiate sub-resource:

public class subresourcefactory { @autowired private autowirecapablebeanfactory autowirebeanfactory; public subresource createbean(string parameter1, parameter2 parameter2) { ... creating subresource instance, setting parameters autowirebeanfactory.autowirebean(subresource); homecoming (subresource) autowirebeanfactory.initializebean(subresource, "subresource"); } }

autowirecapablebeanfactory allows init bean created outside of spring context , inject spring beans it. subresourcefactory instantiated spring singleton bean in project , injected in root resource, can utilize this:

@resource private subresourcefactory subresourcefactory; @override public subresource getinfofromsubresource(string parameter1) { parameter2 parameter2 = parameter2storeservice.getparameter2(parameter1); homecoming subresourcefactory.createbean(parameter1, parameter2); }

but subresource managed spring, can inject spring beans, can not inject cxf-rs @context beans. there must way same thing allow spring , cxf-rs injections resourcecontext, can see now, injects cxf-rs beans, no spring @ all.

spring cxf jax-rs

No comments:

Post a Comment